From 677ca99ec4a5f59ded23e57ec860c366038b715c Mon Sep 17 00:00:00 2001 From: timea Date: Wed, 12 Jan 2022 01:15:19 +0000 Subject: [PATCH 1/5] exercise B --- 1-exercises/B-while-loop/exercise.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/1-exercises/B-while-loop/exercise.js b/1-exercises/B-while-loop/exercise.js index b459888f..fd6fe3b4 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(0)) -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 From 9f49926fbbceaa5b4182cbb4dfa090b3be3e344e Mon Sep 17 00:00:00 2001 From: timea Date: Fri, 14 Jan 2022 12:59:13 +0000 Subject: [PATCH 2/5] mandatory exercise 1 and 2 done --- 1-exercises/A-undefined/exercise.js | 12 ++++++------ 1-exercises/B-while-loop/exercise.js | 2 +- 1-exercises/C-while-loop-with-array/exercise.js | 7 ++++++- 1-exercises/D-do-while/exercise.js | 13 ++++++++++--- 1-exercises/E-for-loop/exercise1.js | 12 ++++++++---- 1-exercises/E-for-loop/exercise2.js | 11 ++++++++++- 1-exercises/F-for-of-loop/exercise.js | 7 +++++++ 2-mandatory/1-weather-report.js | 7 ++++++- 2-mandatory/2-retrying-random-numbers.js | 11 +++++++++-- 2-mandatory/3-financial-times.js | 10 ++++++++-- 10 files changed, 71 insertions(+), 21 deletions(-) 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 fd6fe3b4..0c02497f 100644 --- a/1-exercises/B-while-loop/exercise.js +++ b/1-exercises/B-while-loop/exercise.js @@ -15,7 +15,7 @@ function evenNumbers(n) { } return evenNum; } -console.log(evenNumbers(0)) +console.log(evenNumbers(3)) // evenNumbers(3); // should output 0,2,4 // evenNumbers(0); // should output nothing 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..4b61f08d 100644 --- a/2-mandatory/3-financial-times.js +++ b/2-mandatory/3-financial-times.js @@ -5,7 +5,13 @@ 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 Date: Fri, 14 Jan 2022 21:39:26 +0000 Subject: [PATCH 3/5] mandatory 3 finished, 4 attempted --- 2-mandatory/3-financial-times.js | 67 +++++++++++++++++++++++--------- 2-mandatory/4-stocks.js | 37 ++++++++++++------ 2 files changed, 75 insertions(+), 29 deletions(-) diff --git a/2-mandatory/3-financial-times.js b/2-mandatory/3-financial-times.js index 4b61f08d..49e3dce9 100644 --- a/2-mandatory/3-financial-times.js +++ b/2-mandatory/3-financial-times.js @@ -4,14 +4,19 @@ 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) { 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! @@ -29,34 +46,48 @@ 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..4375f57c 100644 --- a/2-mandatory/4-stocks.js +++ b/2-mandatory/4-stocks.js @@ -8,15 +8,7 @@ */ /* ======= Stock data - DO NOT MODIFY ===== */ -const STOCKS = ["aapl", "msft", "amzn", "googl", "tsla"]; -const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [ - [179.19, 180.33, 176.28, 175.64, 172.99], // AAPL - [340.69, 342.45, 334.69, 333.20, 327.29], // MSFT - [3384.44, 3393.39, 3421.37, 3420.74, 3408.34], // AMZN - [2951.88, 2958.13, 2938.33, 2928.30, 2869.45], // GOOGL - [1101.30, 1093.94, 1067.00, 1008.87, 938.53] // TSLA -]; /* We want to understand what the average price over the last 5 days for each stock is. @@ -34,8 +26,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 Date: Sat, 15 Jan 2022 00:39:03 +0000 Subject: [PATCH 4/5] fixed mandatory exercise 3 --- 2-mandatory/3-financial-times.js | 31 ++++++++++++++----------------- 2-mandatory/4-stocks.js | 10 +++++++++- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/2-mandatory/3-financial-times.js b/2-mandatory/3-financial-times.js index 49e3dce9..b5b0ea1c 100644 --- a/2-mandatory/3-financial-times.js +++ b/2-mandatory/3-financial-times.js @@ -12,9 +12,6 @@ function potentialHeadlines(allArticleTitles) { if (allArticleTitles[i].length <= 65 ){ newArr.push(allArticleTitles[i]) } - else { - return newArr; - } } return newArr; } @@ -65,27 +62,27 @@ function averageNumberOfCharacters(allArticleTitles) { let sum= 0; for (let i=0; i Date: Sat, 15 Jan 2022 00:53:53 +0000 Subject: [PATCH 5/5] fixed mandatory exercise 4 --- 2-mandatory/4-stocks.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/2-mandatory/4-stocks.js b/2-mandatory/4-stocks.js index e05feb90..60a97b22 100644 --- a/2-mandatory/4-stocks.js +++ b/2-mandatory/4-stocks.js @@ -37,15 +37,15 @@ function getAveragePrices(closingPricesForAllStocks) { 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]