From ef856c31a3fb5e26cfe718b56cfdbe9c18e70a59 Mon Sep 17 00:00:00 2001 From: NetMan <13informatyka14@gmail.com> Date: Sat, 30 Dec 2023 15:11:09 +0100 Subject: [PATCH] Initlal commit --- 01-troubleshooting/index.js | 14 ++++ 01-troubleshooting/troubleshooting.js | 24 ++++++ 02-enter-a-number/index.html | 57 +++++++++++++ 02-enter-a-number/script.js | 16 ++++ 02-enter-a-number/style.css | 0 03-lets-do-some-math/index.js | 36 +++++++++ 03-lets-do-some-math/math.js | 14 ++++ 04-direction-follow/follow.js | 111 ++++++++++++++++++++++++++ 04-direction-follow/index.js | 84 +++++++++++++++++++ README.md | 2 + 10 files changed, 358 insertions(+) create mode 100644 01-troubleshooting/index.js create mode 100644 01-troubleshooting/troubleshooting.js create mode 100644 02-enter-a-number/index.html create mode 100644 02-enter-a-number/script.js create mode 100644 02-enter-a-number/style.css create mode 100644 03-lets-do-some-math/index.js create mode 100644 03-lets-do-some-math/math.js create mode 100644 04-direction-follow/follow.js create mode 100644 04-direction-follow/index.js create mode 100644 README.md diff --git a/01-troubleshooting/index.js b/01-troubleshooting/index.js new file mode 100644 index 0000000..f80b46a --- /dev/null +++ b/01-troubleshooting/index.js @@ -0,0 +1,14 @@ +// I get it, you're curious, +// but it's OK if you don't understand what's going on in here, you'll learn it in time. + +const abTroubleshoot = require("./troubleshooting"); + +const result = abTroubleshoot(); + +if(result === 2) { + console.log("Congrats! You got the correct answer"); +} else if(typeof result === 'number') { + console.log(`You returned the number ${result}, the result should be the number 2`); +} else { + console.log(`You returned string "${result}", the result should be the number 2`); +} diff --git a/01-troubleshooting/troubleshooting.js b/01-troubleshooting/troubleshooting.js new file mode 100644 index 0000000..f6dbeb6 --- /dev/null +++ b/01-troubleshooting/troubleshooting.js @@ -0,0 +1,24 @@ +/** + * ===== Troubleshooting ===== + * The function below should log the number 2, however it does not, + * see if you can fix it! + * Be sure to fix it in the spirit of the code, do not hard code the result. + */ + +function troubleshooting() { + const a = 1; + const b = 1; + + let result; + + // Edit between these lines + // ================================= + result = "a" + "b"; + + // ================================= + + return result; +} + +// Do not change this +module.exports = troubleshooting; diff --git a/02-enter-a-number/index.html b/02-enter-a-number/index.html new file mode 100644 index 0000000..1ad5b0d --- /dev/null +++ b/02-enter-a-number/index.html @@ -0,0 +1,57 @@ + + + + + + + repl.it + + + + +

Be sure to enable the "developer" tools! (It's the wrench icon in replit)

+ + + + + + diff --git a/02-enter-a-number/script.js b/02-enter-a-number/script.js new file mode 100644 index 0000000..4afaa72 --- /dev/null +++ b/02-enter-a-number/script.js @@ -0,0 +1,16 @@ +/** + * The code below tells the browser to ask you for a number + * then if that number is `6`, it returns `true` otherwise it returns `false` + * + * Change this code so it returns `true` when the number is greater than or equal to 10, and false if it is less than 10 + */ + +number = Number(prompt("enter a number")); + +function numberChecker() { + if(number === 6) { + return true; + } else { + return false; + } +} diff --git a/02-enter-a-number/style.css b/02-enter-a-number/style.css new file mode 100644 index 0000000..e69de29 diff --git a/03-lets-do-some-math/index.js b/03-lets-do-some-math/index.js new file mode 100644 index 0000000..e6cf3a0 --- /dev/null +++ b/03-lets-do-some-math/index.js @@ -0,0 +1,36 @@ +const { a, b, c, d, e } = require("./math"); + +if (a === 9) { + console.log("'a' is correct!") +} else { + console.log(`'a' is incorrect, got ${a}, expected 9`) +} +console.log("\n"); + +if (b === 66) { + console.log("'b' is correct!") +} else { + console.log(`'b' is incorrect, got ${b}, expected 66`) +} +console.log("\n"); + +if (c === 1) { + console.log("'c' is correct!") +} else { + console.log(`'c' is incorrect, got ${c}, expected 1`) +} +console.log("\n"); + +if (d === -8) { + console.log("'d' is correct!") +} else { + console.log(`'d' is incorrect, got ${d}, expected -8`) +} +console.log("\n"); + +if (e === 68) { + console.log("'e' is correct!") + console.log("\n Congrats! You may move onto the next exercise") +} else { + console.log(`'e' is incorrect, got ${e}, expected 68`) +} diff --git a/03-lets-do-some-math/math.js b/03-lets-do-some-math/math.js new file mode 100644 index 0000000..ec2f4a2 --- /dev/null +++ b/03-lets-do-some-math/math.js @@ -0,0 +1,14 @@ +/** + * Lets do some math! + * Some rules first: + * - Replace the strings to the right of the = with the math expression they describe. + * - Do not manually enter the answers to the equations. For example, `const a = 9` would be incorrect as 9 is the answer to the equation you're being asked to write out + */ + +const a = "one plus eight" +const b = "22 times three" +const c = "the *remainder* of 5/4" +const d = "the variable 'a' minus 17" +const e = "the sum of the previous four variables" + +module.exports = {a, b, c, d, e} diff --git a/04-direction-follow/follow.js b/04-direction-follow/follow.js new file mode 100644 index 0000000..3ac88bc --- /dev/null +++ b/04-direction-follow/follow.js @@ -0,0 +1,111 @@ +/** +- After each step, run the code to make sure your code still works! + +- If your code fails to run, or you see a "ReferenceError" in the console, review your code and make sure you have completed all of the objectives. + +- Don't forget you can put "console.log" anywhere to see what your values are at any time. + + ===== Step 1: ===== + Look at the code below and make a prediction of what the output will be. + + After making your prediction, press 'Run' at the top and look at the output in the console. If you were surprised by anything, go back and look at the code to see what's going on. + +*/ + +// code to be deleted +const birthYear = 1948; +const thisYear = 1965; +const firstName = "Carlos"; +const lastName = "Stevenson"; + +const greeting = "Hello! My name is " + firstName + " " + lastName + " and I am " + (thisYear - birthYear) + " years old."; + +console.log(greeting); + +/* + + ===== Step 2: ===== + Once you understand the code snippet above, delete it. Then, using the following instructions, recreate the snippet on your own under "Your code goes here". + + --------------------------------------------------------------- + + 1. Create 4 variables: firstName, lastName, thisYear, and birthYear + + 2. Create a 5th variable, greeting, that is constructed from the previous 4 + (it should contain a greeting with the person's full name and their age) + + 3. Print greeting with console.log + + 4. Press 'Run' to ensure your code works + + --------------------------------------------------------------- + + ===== NOTE ===== + In order to make the tests pass you will need to use these exact values. The wording also needs to be an exact match. If the tests fail, check spacing, capitalization, and punctuation: + + birth year = 1948 + this year = 1965 + first name = Carlos + last name = Stevenson + + The greeting should say: "Hello! My name is Carlos Stevenson and I am 17 years old." + +*/ + +//===== Your code goes here ================= + + +/* + + ===== Step 3: ===== + Now that you have the code working again, let's go back over it and, using the instructions below, edit it to make it easier to read. + + --------------------------------------------------------------- + + 1. Go to "Testing your code" below + + 2. Comment out the lines under "Test Step 2" + + 3. Uncomment the lines under "Test Step 3" (Notice the difference between them) + + 4. Go back to your code and create 2 new variables: "fullName" and "age" + + Do NOT simply type the full name and age into the new variables. Set them using the pre-existing variables, with the calculations that are currently inside of greeting. + + 5. Edit the greeting string to use fullName and age instead of the other 4 variables. (the greeting should then look something like: "Hello! My name is " + fullName) + + 6. Press 'Run' to ensure your code still works (output should be unchanged) + + --------------------------------------------------------------- + + ===== Testing your code ===== + - Do NOT edit this section until told to do so. + + - Make sure one and only one of these test steps are commented out at a time + +*/ + +// Test Step 2: + +module.exports = { + testGroup: "a", + greeting, + birthYear, + thisYear, + firstName, + lastName +} + + +// Test Step 3: (Don't forget to comment out lines under Test Step 2) + +// module.exports = { +// testGroup: "b", +// greeting, +// birthYear, +// thisYear, +// firstName, +// lastName, +// fullName, +// age +// } diff --git a/04-direction-follow/index.js b/04-direction-follow/index.js new file mode 100644 index 0000000..79e298f --- /dev/null +++ b/04-direction-follow/index.js @@ -0,0 +1,84 @@ + + +const values = require("./follow"); +let errored = false; + +console.log("\n---------------------------------\n\n") + +if(values.testGroup === "a") { + if(values.birthYear !== 1948) { + console.error(`birthYear is incorrect, it's currently: "${values.birthYear}"`); + errored = true; + } + + if(values.thisYear !== 1965) { + console.error(`thisYear is incorrect, it's currently: "${values.thisYear}"`); + errored = true; + } + + if(values.firstName !== "Carlos") { + console.error(`firstName is incorrect, it's currently: "${values.firstName}"`); + errored = true; + } + + if(values.lastName !== "Stevenson") { + console.error(`lastName is incorrect, it's currently: "${values.lastName}"`); + errored = true; + } + + if(values.greeting !== "Hello! My name is Carlos Stevenson and I am 17 years old.") { + console.error(`greeting is incorrect, it's currently: "${values.greeting}"`); + errored = true; + } +} + +if(values.testGroup === "b") { + if(values.birthYear !== 1948) { + console.error(`birthYear is incorrect, it's currently: "${values.birthYear}"`); + errored = true; + } + + if(values.thisYear !== 1965) { + console.error(`thisYear is incorrect, it's currently: "${values.thisYear}"`); + errored = true; + } + + if(values.firstName !== "Carlos") { + console.error(`firstName is incorrect, it's currently: "${values.firstName}"`); + errored = true; + } + + if(values.lastName !== "Stevenson") { + console.error(`lastName is incorrect, it's currently: "${values.lastName}"`); + errored = true; + } + + if(values.age !== 17) { + console.error(`age is incorrect, it's currently: "${values.age}"`); + errored = true; + } + + if(values.fullName !== "Carlos Stevenson") { + console.error(`fullName is incorrect, it's currently: "${values.fullName}"`); + errored = true; + } + + if(values.greeting !== "Hello! My name is Carlos Stevenson and I am 17 years old.") { + console.error(`greeting is incorrect, it's currently: "${values.greeting}"`); + errored = true; + } +} + +if(!errored && values.testGroup === "a") { + console.log("Congrats! Move onto the next step!"); +} else if (errored && values.testGroup === "a") { + console.log("Try again") +} + +if(!errored && values.testGroup === "b") { + console.log("Congrats! Move onto the next lesson!"); +} else if (errored) { + console.log("Try again") +} + +console.log("\n---------------------------------\n\n") diff --git a/README.md b/README.md new file mode 100644 index 0000000..506aa4d --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# odin JS Fundamentals Part 2 exercises +assignment for [this lesson](https://www.theodinproject.com/lessons/foundations-fundamentals-part-2#assignment) provided on replit