diff --git a/1-exercises/A-undefined/exercise.js b/1-exercises/A-undefined/exercise.js index 0acfc78d..33a23be9 100644 --- a/1-exercises/A-undefined/exercise.js +++ b/1-exercises/A-undefined/exercise.js @@ -12,16 +12,18 @@ // Example 1 let a; console.log(a); +// we have not assigned a value to 'a' e.g let a = "something" // Example 2 function sayHello() { let message = "Hello"; + } let hello = sayHello(); console.log(hello); - +// we needed a 'return message' inside the function // Example 3 function sayHelloToUser(user) { @@ -30,7 +32,10 @@ function sayHelloToUser(user) { sayHelloToUser(); +// you haven't given the function a parameter e.g "khadija" + // Example 4 let arr = [1,2,3]; console.log(arr[3]); +// the index 3 does not exist in the given array but if we added an extra number e.g 4, it would no longer be undefined. diff --git a/1-exercises/B-while-loop/exercise.js b/1-exercises/B-while-loop/exercise.js index b459888f..c160cacb 100644 --- a/1-exercises/B-while-loop/exercise.js +++ b/1-exercises/B-while-loop/exercise.js @@ -6,9 +6,24 @@ */ function evenNumbers(n) { - // TODO + // TODO '*' +if(n!== 0){ + let i = 0; + let j = 0; + let array = []; + + while(i < n){ + array.push(j); + i++; + j = (j+2); + } + + console.log(array.toString()); + } } + + evenNumbers(3); // should output 0,2,4 evenNumbers(0); // should output nothing evenNumbers(10); // should output 0,2,4,6,8,10,12,14,16,18 diff --git a/1-exercises/C-while-loop-with-array/exercise.js b/1-exercises/C-while-loop-with-array/exercise.js index d584cd75..58efd727 100644 --- a/1-exercises/C-while-loop-with-array/exercise.js +++ b/1-exercises/C-while-loop-with-array/exercise.js @@ -18,6 +18,13 @@ const BIRTHDAYS = [ function findFirstJulyBDay(birthdays) { // 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/2-mandatory/1-weather-report.js b/2-mandatory/1-weather-report.js index dcc2bdb0..7fc0b793 100644 --- a/2-mandatory/1-weather-report.js +++ b/2-mandatory/1-weather-report.js @@ -12,7 +12,13 @@ */ function getTemperatureReport(cities) { - // TODO + let cityWeather = []; + for (let i = 0; i < cities.length; i++) { + cityWeather.push( + `The temperature in ${cities[i]} is ${temperatureService(cities[i])} degrees` + ); + } + return cityWeather; } @@ -31,7 +37,7 @@ function temperatureService(city) { return temparatureMap.get(city); } - +temperatureService("London") test("should return a temperature report for the user's cities", () => { let usersCities = [ "London", diff --git a/2-mandatory/2-retrying-random-numbers.js b/2-mandatory/2-retrying-random-numbers.js index 10aab37d..0d0a1aca 100644 --- a/2-mandatory/2-retrying-random-numbers.js +++ b/2-mandatory/2-retrying-random-numbers.js @@ -11,6 +11,11 @@ function generateRandomNumber() { function getRandomNumberGreaterThan50() { // TODO - implement using a do-while loop + let n; + do { + n = generateRandomNumber(); + } while (n < 50) + return n } /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/2-mandatory/4-stocks.js b/2-mandatory/4-stocks.js index 72d62f94..65a884ab 100644 --- a/2-mandatory/4-stocks.js +++ b/2-mandatory/4-stocks.js @@ -37,6 +37,7 @@ function getAveragePrices(closingPricesForAllStocks) { // TODO } + /* We also want to see what the change in price is from the first day to the last day for each stock. Implement the below function, which