diff --git a/1-exercises/A-undefined/exercise.js b/1-exercises/A-undefined/exercise.js index 0acfc78d..bec36e60 100644 --- a/1-exercises/A-undefined/exercise.js +++ b/1-exercises/A-undefined/exercise.js @@ -11,26 +11,23 @@ // Example 1 let a; -console.log(a); - +console.log(a); // a is declared as a variable. But no value has been assigned // Example 2 function sayHello() { - let message = "Hello"; + let message = "Hello"; // This function does not return anything, so definition is not enough. } let hello = sayHello(); -console.log(hello); - +console.log(hello); // Variable defined but function must be defined too. // Example 3 function sayHelloToUser(user) { - console.log(`Hello ${user}`); + console.log(`Hello ${user}`); } -sayHelloToUser(); - +sayHelloToUser(); // user declared as a parameter. But when calling a function, an argument is needed not to get undefined result // Example 4 -let arr = [1,2,3]; -console.log(arr[3]); +let arr = [1, 2, 3]; +console.log(arr[3]); // The index has been given is not existing or NOT DEFINED in the variable diff --git a/1-exercises/B-while-loop/exercise.js b/1-exercises/B-while-loop/exercise.js index b459888f..27dac1d3 100644 --- a/1-exercises/B-while-loop/exercise.js +++ b/1-exercises/B-while-loop/exercise.js @@ -6,7 +6,14 @@ */ function evenNumbers(n) { - // TODO + // TODO + const arr = []; + let i = 0; + while (i < n) { + arr.push(2 * i); + i++; + } + console.log(arr.toString()); } evenNumbers(3); // should output 0,2,4 diff --git a/1-exercises/C-while-loop-with-array/exercise.js b/1-exercises/C-while-loop-with-array/exercise.js index d584cd75..a94b4784 100644 --- a/1-exercises/C-while-loop-with-array/exercise.js +++ b/1-exercises/C-while-loop-with-array/exercise.js @@ -5,19 +5,27 @@ */ const BIRTHDAYS = [ - "January 7th", - "February 12th", - "April 3rd", - "April 5th", - "May 3rd", - "July 11th", - "July 17th", - "September 28th", - "November 15th" + "January 7th", + "February 12th", + "April 3rd", + "April 5th", + "May 3rd", + "July 11th", + "July 17th", + "September 28th", + "November 15th", ]; function findFirstJulyBDay(birthdays) { - // TODO + // TODO + + let i = 0; + while (i < birthdays.length) { + if (birthdays[i].includes("July")) { + return birthdays[i]; + } + i++; + } } console.log(findFirstJulyBDay(BIRTHDAYS)); // should output "July 11th" diff --git a/1-exercises/D-do-while/exercise.js b/1-exercises/D-do-while/exercise.js index f10d0764..d577a850 100644 --- a/1-exercises/D-do-while/exercise.js +++ b/1-exercises/D-do-while/exercise.js @@ -8,6 +8,13 @@ function evenNumbersSum(n) { // TODO + let sum = 0; + let i = 0; + do { + sum += 2 * i; + i++; + }while (i < n); + return sum; } console.log(evenNumbersSum(3)); // should output 6