From 70d9d3b089a44eb0ebbcef9c802864d65a177c96 Mon Sep 17 00:00:00 2001 From: Zahraa <113244988+ZahraaTayyar@users.noreply.github.com> Date: Mon, 5 Dec 2022 16:12:55 +0000 Subject: [PATCH 1/3] exercise b --- 1-exercises/A-undefined/exercise.js | 8 ++++---- 1-exercises/B-while-loop/exercise.js | 8 ++++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/1-exercises/A-undefined/exercise.js b/1-exercises/A-undefined/exercise.js index 0acfc78d..340f9b2a 100644 --- a/1-exercises/A-undefined/exercise.js +++ b/1-exercises/A-undefined/exercise.js @@ -11,7 +11,7 @@ // Example 1 let a; -console.log(a); +console.log(a); //'a' hasn't been assigned a variable // Example 2 @@ -20,7 +20,7 @@ function sayHello() { } let hello = sayHello(); -console.log(hello); +console.log(hello); //function doesn't return anything // Example 3 @@ -28,9 +28,9 @@ function sayHelloToUser(user) { console.log(`Hello ${user}`); } -sayHelloToUser(); +sayHelloToUser(); //user not defined // Example 4 let arr = [1,2,3]; -console.log(arr[3]); +console.log(arr[3]); //arrays start at 0, there is no 3rd variable diff --git a/1-exercises/B-while-loop/exercise.js b/1-exercises/B-while-loop/exercise.js index b459888f..3a16d73b 100644 --- a/1-exercises/B-while-loop/exercise.js +++ b/1-exercises/B-while-loop/exercise.js @@ -1,12 +1,16 @@ /* while loops can be useful when you want to execute some code as long as some condition is true. - Using a while loop, complete the function below so it logs (using console.log) the first n even numbers as a comma-seperated string. + Using a while loop, complete the function below so it logs (using console.log) the first n even numbers as a comma-separated string. The list of numbers should start with 0. n is being passed in as a parameter. */ function evenNumbers(n) { - // TODO + let i = 0; + while (i <= n) { + console.log(i); + i = i + 2; + } } evenNumbers(3); // should output 0,2,4 From a278f75ab5efeef1856978a3235297eeb6c90eef Mon Sep 17 00:00:00 2001 From: Zahraa <113244988+ZahraaTayyar@users.noreply.github.com> Date: Fri, 9 Dec 2022 15:40:12 +0000 Subject: [PATCH 2/3] exercise E --- 1-exercises/A-undefined/exercise.js | 7 +++---- 1-exercises/B-while-loop/exercise.js | 13 +++++++++--- .../C-while-loop-with-array/exercise.js | 11 +++++++--- 1-exercises/D-do-while/exercise.js | 20 +++++++++++++++---- 1-exercises/E-for-loop/exercise1.js | 3 +-- 1-exercises/E-for-loop/exercise2.js | 3 +++ 6 files changed, 41 insertions(+), 16 deletions(-) diff --git a/1-exercises/A-undefined/exercise.js b/1-exercises/A-undefined/exercise.js index 340f9b2a..1c0c842a 100644 --- a/1-exercises/A-undefined/exercise.js +++ b/1-exercises/A-undefined/exercise.js @@ -11,7 +11,7 @@ // Example 1 let a; -console.log(a); //'a' hasn't been assigned a variable +console.log(a); //'a' hasn't been assigned a value // Example 2 @@ -28,9 +28,8 @@ function sayHelloToUser(user) { console.log(`Hello ${user}`); } -sayHelloToUser(); //user not defined - +sayHelloToUser(); //no argument given when calling the function. // Example 4 let arr = [1,2,3]; -console.log(arr[3]); //arrays start at 0, there is no 3rd variable +console.log(arr[3]); //The arrays start at 0, there is no array item at the 3rd index. diff --git a/1-exercises/B-while-loop/exercise.js b/1-exercises/B-while-loop/exercise.js index 3a16d73b..3998566e 100644 --- a/1-exercises/B-while-loop/exercise.js +++ b/1-exercises/B-while-loop/exercise.js @@ -7,12 +7,19 @@ function evenNumbers(n) { let i = 0; - while (i <= n) { - console.log(i); + let count = 1; + let zahraasBag = []; + + while (count <= n) { + // console.log(`Loop${count} i:${i} n:${n} count:${count}`); + count = count + 1; + zahraasBag.push(i); i = i + 2; } + + console.log(zahraasBag.join()); } 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(10); // should output 0,2,4,6,8,10,12,14,16,18 \ No newline at end of file diff --git a/1-exercises/C-while-loop-with-array/exercise.js b/1-exercises/C-while-loop-with-array/exercise.js index d584cd75..5ab4b3a0 100644 --- a/1-exercises/C-while-loop-with-array/exercise.js +++ b/1-exercises/C-while-loop-with-array/exercise.js @@ -16,8 +16,13 @@ const BIRTHDAYS = [ "November 15th" ]; -function findFirstJulyBDay(birthdays) { - // TODO +function findFirstJulyBDay(theToasterYouAreGoingToGiveMe) { + for (let pieceOfToast of theToasterYouAreGoingToGiveMe) { + // console.log(pieceOfToast); + if (pieceOfToast.includes("July")) { + return pieceOfToast; + } + } } -console.log(findFirstJulyBDay(BIRTHDAYS)); // should output "July 11th" +console.log(findFirstJulyBDay(BIRTHDAYS)); // should output "July 11th" \ No newline at end of file diff --git a/1-exercises/D-do-while/exercise.js b/1-exercises/D-do-while/exercise.js index f10d0764..fc2924e3 100644 --- a/1-exercises/D-do-while/exercise.js +++ b/1-exercises/D-do-while/exercise.js @@ -7,9 +7,21 @@ */ function evenNumbersSum(n) { - // TODO + + let i = 0; + let count = 1; + let sum = 0; + + do { + i = i + 2; + count = count + 1; + sum = sum + i; + // console.log(sum); + } while (count < n); + + return sum; } -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(3)); // should output 6 0+2+4 = 6 +console.log(evenNumbersSum(0)); // should output 0 0 +console.log(evenNumbersSum(10)); // should output 90 0+2+4+6+8+10+12+14+16+18 = 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..05683c37 100644 --- a/1-exercises/E-for-loop/exercise1.js +++ b/1-exercises/E-for-loop/exercise1.js @@ -7,8 +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++; } // 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..73b48718 100644 --- a/1-exercises/E-for-loop/exercise2.js +++ b/1-exercises/E-for-loop/exercise2.js @@ -28,6 +28,9 @@ const AGES = [ // TODO - Write for loop code here +i = 0; +for (let ) + /* The output should look something like this: From ac78051af9dc767ae5174d195a84e7f3cdc0bd77 Mon Sep 17 00:00:00 2001 From: Zahraa <113244988+ZahraaTayyar@users.noreply.github.com> Date: Sat, 10 Dec 2022 12:37:04 +0000 Subject: [PATCH 3/3] Update 3-financial-times.js --- 2-mandatory/3-financial-times.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/2-mandatory/3-financial-times.js b/2-mandatory/3-financial-times.js index 2ce6fb73..d5bd045c 100644 --- a/2-mandatory/3-financial-times.js +++ b/2-mandatory/3-financial-times.js @@ -5,7 +5,16 @@ Implement the function below, which will return a new array containing only article titles which will fit. */ function potentialHeadlines(allArticleTitles) { - // TODO + let headlines = []; + + for (headline) +} + + +function numberOfWords(title) { + // return no. of words in title + let wordsArray = title.split(' ').length + return wordsArray } /* @@ -14,7 +23,17 @@ function potentialHeadlines(allArticleTitles) { (you can assume words will always be seperated by a space) */ function titleWithFewestWords(allArticleTitles) { - // TODO + let lowestNumberOfWords; + let titleWithFewestWords; + + for (let title of allArticleTitles) { + let numWords = numberOfWords(title); + if (lowestNumberOfWords === undefined || numWords < lowestNumberOfWords) { + lowestNumberOfWords = numWords; + titleWithFewestWords = title; + } + } + return titleWithFewestWords; } /*