From c7331c5bf40dd5c73d031ef830056cd306a9a80e Mon Sep 17 00:00:00 2001 From: ArnauACR <145784953+ArnauACR@users.noreply.github.com> Date: Sun, 17 Nov 2024 19:54:33 +0100 Subject: [PATCH 1/3] FIX: Exercises renove --- loops-conditionals/conditionals/exercise_02.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/loops-conditionals/conditionals/exercise_02.js b/loops-conditionals/conditionals/exercise_02.js index 4e7f1e0..707d0ff 100644 --- a/loops-conditionals/conditionals/exercise_02.js +++ b/loops-conditionals/conditionals/exercise_02.js @@ -7,6 +7,7 @@ const age = 20; +function checkAge(){ if (age < 3) { console.log("You're just a baby!"); return; @@ -25,3 +26,7 @@ if (age >= 18) { } console.log("What? How did this happen!?"); +return +} + +checkAge() From d8f0ee64c5d5a6c2e4ed4b07e7e2e147e7e61bed Mon Sep 17 00:00:00 2001 From: ArnauACR <145784953+ArnauACR@users.noreply.github.com> Date: Sun, 17 Nov 2024 20:01:14 +0100 Subject: [PATCH 2/3] ADD: index.html --- index.html | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 index.html diff --git a/index.html b/index.html new file mode 100644 index 0000000..cde6fff --- /dev/null +++ b/index.html @@ -0,0 +1,19 @@ + + + + + + 03_JavaScript-foundations__loops-conditionals + + + + + + + + + + + + + From a21b6f05cb2948e067d00e26ade739b2c4190272 Mon Sep 17 00:00:00 2001 From: ArnauACR <145784953+ArnauACR@users.noreply.github.com> Date: Sun, 17 Nov 2024 20:48:57 +0100 Subject: [PATCH 3/3] ADD: Completly exercises --- .../conditionals/exercise_00.js | 31 +++++++++++++++++++ .../conditionals/exercise_01.js | 12 +++++++ .../conditionals/exercise_02.js | 2 +- loops-conditionals/loops/exercise_00.js | 16 ++++++++++ loops-conditionals/loops/exercise_01.js | 11 +++++++ loops-conditionals/loops/exercise_02.js | 16 ++++++++++ loops-conditionals/while/exercise_00.js | 24 ++++++++++++++ loops-conditionals/while/exercise_01.js | 20 ++++++++++++ loops-conditionals/while/exercise_02.js | 14 +++++++++ 9 files changed, 145 insertions(+), 1 deletion(-) diff --git a/loops-conditionals/conditionals/exercise_00.js b/loops-conditionals/conditionals/exercise_00.js index 3b9c2ee..31828f3 100644 --- a/loops-conditionals/conditionals/exercise_00.js +++ b/loops-conditionals/conditionals/exercise_00.js @@ -8,3 +8,34 @@ 7. At the end of the program, print out: "--- Animal check complete ---" 8. Change the animal to different values to make sure it works in all cases */ +// exercise1.js + +// 1 + +console.log("--- Animal Checker Program --"); + +// 2 + +let animal = "cat"; + +// 3 + +if (animal === "cat") { + console.log("Meow"); +} + +// 5 + +else if (animal === "dog") { + console.log("Woof"); +} + +// 6 + +else { + console.log("Must be an alien"); +} + +// 7 + +console.log("--- Animal check complete ---"); diff --git a/loops-conditionals/conditionals/exercise_01.js b/loops-conditionals/conditionals/exercise_01.js index 763d3cc..b3f5e3d 100644 --- a/loops-conditionals/conditionals/exercise_01.js +++ b/loops-conditionals/conditionals/exercise_01.js @@ -7,3 +7,15 @@ HINT: The modulus operator ( % ) is your friend. */ + +// 1 + +let number = 8; + +// 2 + +if (number % 2 === 0) { + console.log(`Number ${number} is even`); +} else { + console.log(`Number ${number} is odd`); +} diff --git a/loops-conditionals/conditionals/exercise_02.js b/loops-conditionals/conditionals/exercise_02.js index 707d0ff..05d448d 100644 --- a/loops-conditionals/conditionals/exercise_02.js +++ b/loops-conditionals/conditionals/exercise_02.js @@ -4,7 +4,7 @@ Add a comment explaining what is happenning and how to fix it */ - +//The poblem is in the returns, because the first if is completly and return ""You are in elementary school, kid." this text is printed but no is true the solution is or change the order to major if comaprison to minor o delete de equals " const age = 20; function checkAge(){ diff --git a/loops-conditionals/loops/exercise_00.js b/loops-conditionals/loops/exercise_00.js index 5558dc8..b695c42 100644 --- a/loops-conditionals/loops/exercise_00.js +++ b/loops-conditionals/loops/exercise_00.js @@ -3,3 +3,19 @@ 2. Create a for loop that will print out all the odd numbers between 10 and 40. */ + +//1 + +for (let i = 10; i <= 40; i++) { + if (i % 2 === 0) { + console.log(i); + } +} + +//2 + +for (let i = 10; i <= 40; i++) { + if (i % 2 !== 0) { + console.log(i); + } +} diff --git a/loops-conditionals/loops/exercise_01.js b/loops-conditionals/loops/exercise_01.js index a2ad819..97209eb 100644 --- a/loops-conditionals/loops/exercise_01.js +++ b/loops-conditionals/loops/exercise_01.js @@ -6,3 +6,14 @@ * If it is greater than or equal to 5, print "Logged In with (number)!" * If it is less than 5, print "Logged Out with (number)!" */ + +for (let i = 1; i <= 10; i++) { + + let number = (Math.random() * 10) | 0 + 1; + + if (number >= 5) { + console.log(`Logged In with (${number})!`); + } else { + console.log(`Logged Out with (${number})!`); + } +} diff --git a/loops-conditionals/loops/exercise_02.js b/loops-conditionals/loops/exercise_02.js index d4f851e..9485a54 100644 --- a/loops-conditionals/loops/exercise_02.js +++ b/loops-conditionals/loops/exercise_02.js @@ -18,3 +18,19 @@ You made it! All done! */ + +for (let i = 1; i <= 100; i++) { + if (i % 10 === 0) { + console.log(`Checkpoint! ${i}`); + } + + if (i === 50) { + console.log("Halfway there!"); + } + + if (i === 100) { + console.log("You made it!"); + } +} + +console.log("All done!"); diff --git a/loops-conditionals/while/exercise_00.js b/loops-conditionals/while/exercise_00.js index 3f5ae8a..85f40a4 100644 --- a/loops-conditionals/while/exercise_00.js +++ b/loops-conditionals/while/exercise_00.js @@ -7,3 +7,27 @@ HINT: Be careful of an infinite loop! */ +//1 + +let loggedIn = false; +let attempts = 0; + +//2 + +while (!loggedIn) { + //3 + + console.log("Incorrect login credentials"); + + //4 + + attempts++; + if (attempts === 3) { + loggedIn = true; + } +} + +//5 + +console.log("Successfully logged in!"); + diff --git a/loops-conditionals/while/exercise_01.js b/loops-conditionals/while/exercise_01.js index 6c85b8e..8296b18 100644 --- a/loops-conditionals/while/exercise_01.js +++ b/loops-conditionals/while/exercise_01.js @@ -3,3 +3,23 @@ 2. Create a while loop that will print out all the odd numbers between 10 and 40. */ + +// 1 + +let number = 10; +while (number <= 40) { + if (number % 2 === 0) { + console.log(number); + } + number++; +} + +// 2 + +number = 10; +while (number <= 40) { + if (number % 2 !== 0) { + console.log(number); + } + number++; +} diff --git a/loops-conditionals/while/exercise_02.js b/loops-conditionals/while/exercise_02.js index 6843abf..d1e8746 100644 --- a/loops-conditionals/while/exercise_02.js +++ b/loops-conditionals/while/exercise_02.js @@ -18,3 +18,17 @@ You made it! All done! */ + +$counter = 1; + +while ($counter <= 100) { + + if ($counter % 10 == 0) { + echo "Checkpoint! $counter\n"; + } + + if ($counter == 50) { + echo "Halfwy there!\n"; + } + +