diff --git a/1-exercises/A-undefined/exercise.js b/1-exercises/A-undefined/exercise.js index 0acfc78d..df1d4502 100644 --- a/1-exercises/A-undefined/exercise.js +++ b/1-exercises/A-undefined/exercise.js @@ -10,27 +10,27 @@ */ // Example 1 -let a; +let a; // a is not assigned any value console.log(a); // Example 2 -function sayHello() { - let message = "Hello"; +function sayHello() { // there is no return statement, and the message variable is defined inside the function so it is not read, + let message = "Hello"; // there are no parameters for the function } -let hello = sayHello(); +let hello = sayHello(); console.log(hello); // Example 3 -function sayHelloToUser(user) { +function sayHelloToUser(user) { // we don't pass any parameters into the function console.log(`Hello ${user}`); } sayHelloToUser(); -// Example 4 +// Example 4 // there is nothing in the array at index 3 let arr = [1,2,3]; console.log(arr[3]); diff --git a/1-exercises/B-while-loop/exercise.js b/1-exercises/B-while-loop/exercise.js index b459888f..0c02497f 100644 --- a/1-exercises/B-while-loop/exercise.js +++ b/1-exercises/B-while-loop/exercise.js @@ -6,9 +6,17 @@ */ function evenNumbers(n) { - // TODO + let i = 0; + let evenNum = ''; + while (n>0) { + evenNum= evenNum + i + ','; + i+=2; + n--; + } + return evenNum; } +console.log(evenNumbers(3)) -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 +// 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..2b414b46 100644 --- a/1-exercises/C-while-loop-with-array/exercise.js +++ b/1-exercises/C-while-loop-with-array/exercise.js @@ -17,7 +17,12 @@ const BIRTHDAYS = [ ]; function findFirstJulyBDay(birthdays) { - // TODO + let firstJulyBirthday= ''; + for (let i=0; i0) { + sum = sum+evenNum; + evenNum=evenNum+2; + n--; + } + return sum } -console.log(evenNumbersSum(3)); // should output 6 +console.log(evenNumbersSum(3)); // should output 6 console.log(evenNumbersSum(0)); // should output 0 -console.log(evenNumbersSum(10)); // should output 90 \ No newline at end of file +console.log(evenNumbersSum(10)); // should output 90 \ No newline at end of file diff --git a/1-exercises/E-for-loop/exercise1.js b/1-exercises/E-for-loop/exercise1.js index db5fac64..d0ae3f5a 100644 --- a/1-exercises/E-for-loop/exercise1.js +++ b/1-exercises/E-for-loop/exercise1.js @@ -6,9 +6,13 @@ // Change the below code to use a for loop instead of a while loop. -let i = 0; -while(i < 26) { +// let i = 0; +// while(i < 26) { +// console.log(String.fromCharCode(97 + i)); +// i++; +// } +// The output shouldn't change. + +for (let i=0; i<26; i++){ console.log(String.fromCharCode(97 + i)); - i++; } -// The output shouldn't change. diff --git a/1-exercises/E-for-loop/exercise2.js b/1-exercises/E-for-loop/exercise2.js index 081002b2..efcd51ed 100644 --- a/1-exercises/E-for-loop/exercise2.js +++ b/1-exercises/E-for-loop/exercise2.js @@ -26,7 +26,16 @@ const AGES = [ 49 ]; -// TODO - Write for loop code here +for (let i=0; i { expect(getRandomNumberGreaterThan50()).toBeGreaterThan(50); diff --git a/2-mandatory/3-financial-times.js b/2-mandatory/3-financial-times.js index 2ce6fb73..b5b0ea1c 100644 --- a/2-mandatory/3-financial-times.js +++ b/2-mandatory/3-financial-times.js @@ -4,8 +4,16 @@ The home page of the web site has a headline section, which only has space for article titles which are 65 characters or less. Implement the function below, which will return a new array containing only article titles which will fit. */ + + function potentialHeadlines(allArticleTitles) { - // TODO + let newArr =[]; + for (let i=0; i allArticleTitles[i].split(" ").length) { + countLength = allArticleTitles[i].split(" ").length + console.log(allArticleTitles[i]) + shortTitle = allArticleTitles[i] + } + } + return shortTitle + } + /* The editor of the FT has realised that headlines which have numbers in them get more clicks! @@ -23,16 +43,30 @@ function titleWithFewestWords(allArticleTitles) { (Hint: remember that you can also loop through the characters of a string if you need to) */ function headlinesWithNumbers(allArticleTitles) { - // TODO + let newArr=[] + for (let i=0; i { expect(new Set(potentialHeadlines(ARTICLE_TITLES))).toEqual(new Set([ diff --git a/2-mandatory/4-stocks.js b/2-mandatory/4-stocks.js index 72d62f94..60a97b22 100644 --- a/2-mandatory/4-stocks.js +++ b/2-mandatory/4-stocks.js @@ -34,8 +34,18 @@ const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [ Functions can help with this! */ function getAveragePrices(closingPricesForAllStocks) { - // TODO + let average =[] + let stockSum =0; + for (let i=0; i { expect(getAveragePrices(CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS)).toEqual( [176.89, 335.66, 3405.66, 2929.22, 1041.93]