diff --git a/1-exercises/A-undefined/exercise.js b/1-exercises/A-undefined/exercise.js index 0acfc78d..0e1161e4 100644 --- a/1-exercises/A-undefined/exercise.js +++ b/1-exercises/A-undefined/exercise.js @@ -12,7 +12,7 @@ // Example 1 let a; console.log(a); - +// There is no value for variable a // Example 2 function sayHello() { @@ -21,7 +21,7 @@ function sayHello() { let hello = sayHello(); console.log(hello); - +//There is no return in function sayHello() // Example 3 function sayHelloToUser(user) { @@ -29,8 +29,10 @@ function sayHelloToUser(user) { } sayHelloToUser(); +//function sayHelloToUser needs an input called user // Example 4 let arr = [1,2,3]; console.log(arr[3]); +// array arr doesn't have index 3 \ No newline at end of file diff --git a/1-exercises/B-while-loop/exercise.js b/1-exercises/B-while-loop/exercise.js index b459888f..f638d744 100644 --- a/1-exercises/B-while-loop/exercise.js +++ b/1-exercises/B-while-loop/exercise.js @@ -7,6 +7,14 @@ function evenNumbers(n) { // TODO + let i = 0 + const arr = [] +while (i < n && n > 0){ + arr.push(i * 2) + console.log(arr[i]) + i++ +} +return arr.join(',') } 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..a611b52c 100644 --- a/1-exercises/C-while-loop-with-array/exercise.js +++ b/1-exercises/C-while-loop-with-array/exercise.js @@ -18,6 +18,8 @@ const BIRTHDAYS = [ function findFirstJulyBDay(birthdays) { // TODO + const findFirstJulyBDay = birthdays.filter((bDay) => bDay.startWith("July")) + return findFirstJulyBDay[0] } 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..1dfd0f32 100644 --- a/1-exercises/D-do-while/exercise.js +++ b/1-exercises/D-do-while/exercise.js @@ -8,6 +8,17 @@ function evenNumbersSum(n) { // TODO + if (n == 0) return 0 + let i = 0 + j = 1 + sum = 0 + do { + i += 2 + sum += i + j ++ + } + while(j < n) + return sum } console.log(evenNumbersSum(3)); // should output 6 diff --git a/1-exercises/E-for-loop/exercise1.js b/1-exercises/E-for-loop/exercise1.js index db5fac64..b8bd470d 100644 --- a/1-exercises/E-for-loop/exercise1.js +++ b/1-exercises/E-for-loop/exercise1.js @@ -7,7 +7,7 @@ // Change the below code to use a for loop instead of a while loop. let i = 0; -while(i < 26) { +for (let i = 0; i < 26; i++) { console.log(String.fromCharCode(97 + i)); i++; } diff --git a/1-exercises/E-for-loop/exercise2.js b/1-exercises/E-for-loop/exercise2.js index 081002b2..4a96c1ea 100644 --- a/1-exercises/E-for-loop/exercise2.js +++ b/1-exercises/E-for-loop/exercise2.js @@ -27,7 +27,9 @@ const AGES = [ ]; // TODO - Write for loop code here - +for (let i = 0; i < WRITERS.length; i++){ + console.log(WRITERS[i]+ ' is ' + AGES[i] + ' years old ') +} /* The output should look something like this: diff --git a/1-exercises/F-for-of-loop/exercise.js b/1-exercises/F-for-of-loop/exercise.js index 65585c6a..d7c0721b 100644 --- a/1-exercises/F-for-of-loop/exercise.js +++ b/1-exercises/F-for-of-loop/exercise.js @@ -10,7 +10,11 @@ let tubeStations = [ "Oxford Street", "Tottenham Court Road" ]; - - +for (let i = 0; i < tubeStations.length; i++){ +console.log(tubeStations[i]); +} // TODO Use a for-of loop to capitalise and output each letter in the string seperately. let str = "codeyourfuture"; +for (let i = 0; i < str.length; i++){ +console.log(str[i].toUpperCase); +} \ No newline at end of file diff --git a/2-mandatory/1-weather-report.js b/2-mandatory/1-weather-report.js index dcc2bdb0..f4e3d727 100644 --- a/2-mandatory/1-weather-report.js +++ b/2-mandatory/1-weather-report.js @@ -13,6 +13,12 @@ function getTemperatureReport(cities) { // TODO + let TemperatureReport = [i]; + for (city of cities){ + let cityTemp = temperatureService(city); + TemperatureReport.push('The temperature in ${city} is ${cityTemp} degrees'); + } + return TemperatureReport; } diff --git a/2-mandatory/2-retrying-random-numbers.js b/2-mandatory/2-retrying-random-numbers.js index 10aab37d..467aa6d1 100644 --- a/2-mandatory/2-retrying-random-numbers.js +++ b/2-mandatory/2-retrying-random-numbers.js @@ -11,6 +11,12 @@ function generateRandomNumber() { function getRandomNumberGreaterThan50() { // TODO - implement using a do-while loop + let x = 0 + do { + x = generateRandomNumber() + } + while(x <= 50) + return x; } /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/2-mandatory/3-financial-times.js b/2-mandatory/3-financial-times.js index 2ce6fb73..8b97c7b9 100644 --- a/2-mandatory/3-financial-times.js +++ b/2-mandatory/3-financial-times.js @@ -6,6 +6,7 @@ */ function potentialHeadlines(allArticleTitles) { // TODO + return allArticleTitles.filter; } /*