diff --git a/1-exercises/A-undefined/exercise.js b/1-exercises/A-undefined/exercise.js index 0acfc78d..19a3ca83 100644 --- a/1-exercises/A-undefined/exercise.js +++ b/1-exercises/A-undefined/exercise.js @@ -9,12 +9,12 @@ For each example, can you explain why we are seeing undefined? */ -// Example 1 +/the letter a was not assigned to anything/ Example 1 let a; console.log(a); -// Example 2 +/there is no parameter set inside the sayHello brackets/ Example 2 function sayHello() { let message = "Hello"; } @@ -23,7 +23,7 @@ let hello = sayHello(); console.log(hello); -// Example 3 +/the full fuction name is not stated in the console log/ Example 3 function sayHelloToUser(user) { console.log(`Hello ${user}`); } @@ -31,6 +31,6 @@ function sayHelloToUser(user) { sayHelloToUser(); -// Example 4 +/the maxiimum number in the array is 2/ Example 4 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..e228137b 100644 --- a/1-exercises/B-while-loop/exercise.js +++ b/1-exercises/B-while-loop/exercise.js @@ -6,6 +6,14 @@ */ function evenNumbers(n) { + let i = 0; + let evenArray = []; + + while (i < n) { + evenArray.push(i * 2); + i++; + } + console.log(evenArray.join(', ')) // TODO } diff --git a/1-exercises/C-while-loop-with-array/exercise.js b/1-exercises/C-while-loop-with-array/exercise.js index d584cd75..005e02bb 100644 --- a/1-exercises/C-while-loop-with-array/exercise.js +++ b/1-exercises/C-while-loop-with-array/exercise.js @@ -17,7 +17,16 @@ const BIRTHDAYS = [ ]; function findFirstJulyBDay(birthdays) { - // TODO -} + let i = 0; + let myBdayCheck; + + while (i < birthdays.length - 1) { + myBdayCheck = birthdays[i]; + if (myBdayCheck.startsWith("July")) { + return myBdayCheck; + } + i++; + } +} 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..00e37942 100644 --- a/1-exercises/D-do-while/exercise.js +++ b/1-exercises/D-do-while/exercise.js @@ -8,6 +8,14 @@ function evenNumbersSum(n) { // TODO + sumNum = 0; + i = 0; + + do { + sumNum = sumNum + i * 2 + i++; + } while ( i < n ); + return sumNum; } 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..fc939e2d 100644 --- a/1-exercises/E-for-loop/exercise1.js +++ b/1-exercises/E-for-loop/exercise1.js @@ -7,8 +7,12 @@ // Change the below code to use a for loop instead of a while loop. let i = 0; -while(i < 26) { + +for (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..92401672 100644 --- a/1-exercises/E-for-loop/exercise2.js +++ b/1-exercises/E-for-loop/exercise2.js @@ -1,3 +1,10 @@ + + + + + + + /* for loops can be useful when we already know exactly how many times we want to loop. @@ -27,7 +34,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..0b3b7b2d 100644 --- a/1-exercises/F-for-of-loop/exercise.js +++ b/1-exercises/F-for-of-loop/exercise.js @@ -10,7 +10,12 @@ let tubeStations = [ "Oxford Street", "Tottenham Court Road" ]; - +for (const station of tubeStations) { +consolelog(tubeStations.toUpperCase()); // 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()) +} +} diff --git a/2-mandatory/1-weather-report.js b/2-mandatory/1-weather-report.js index dcc2bdb0..3cb9dc77 100644 --- a/2-mandatory/1-weather-report.js +++ b/2-mandatory/1-weather-report.js @@ -13,6 +13,13 @@ function getTemperatureReport(cities) { // TODO + + let tempArray = []; +for (let city of cities) { + tempArray.push(`The temperature in ${city} is ${temperatureService(city)} degrees`); +} +return tempArray; + } diff --git a/2-mandatory/2-retrying-random-numbers.js b/2-mandatory/2-retrying-random-numbers.js index 10aab37d..f6e6ca4d 100644 --- a/2-mandatory/2-retrying-random-numbers.js +++ b/2-mandatory/2-retrying-random-numbers.js @@ -11,8 +11,13 @@ function generateRandomNumber() { function getRandomNumberGreaterThan50() { // TODO - implement using a do-while loop -} + let num; + do { + (num = generateRandomNumber()); + } while (num <= 50); + return num; +} /* ======= TESTS - DO NOT MODIFY ===== */ test("Returned value should always be greater than 50", () => { diff --git a/2-mandatory/3-financial-times.js b/2-mandatory/3-financial-times.js index 2ce6fb73..97c17360 100644 --- a/2-mandatory/3-financial-times.js +++ b/2-mandatory/3-financial-times.js @@ -4,8 +4,28 @@ 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. */ +const allArticleTitles = [ + "Streaming wars drive media groups to spend more than $100bn on new content", + "Amazon Prime Video India country head: streaming is driving a TV revolution", + "Aerospace chiefs prepare for bumpy ride in recovery of long-haul flights", + "British companies look to muscle in on US retail investing boom", + "Libor to take firm step towards oblivion on New Year's Day", + "Audit profession unattractive to new recruits, says PwC boss", + "Chinese social media users blast Elon Musk over near miss in space", + "Companies raise over $12tn in 'blockbuster' year for global capital markets", + "The three questions that dominate investment", + "Brussels urges Chile's incoming president to endorse EU trade deal", +]; + function potentialHeadlines(allArticleTitles) { - // TODO + let titles = []; + + for (const title in allArticleTitles) { + if (titles.length <= 65) { + titles.push(title); + } + } + return titles; // TODO } /* @@ -14,7 +34,17 @@ function potentialHeadlines(allArticleTitles) { (you can assume words will always be seperated by a space) */ function titleWithFewestWords(allArticleTitles) { - // TODO + let fewWords = allArticleTitles[0]; + let words = allArticleTitles[0].split(" ").length; + + for (let i = 0; i < allArticleTitles.length; i++) { + let theWordArrapy = allArticleTitles[i].split(" ").length; + if (theWordArray < words) { + fewWords = allArticleTitles[i]; + } + words = theWordArrapy; + } + return fewWords; } /*