From 342a737dfb9962f9c59430a9db23a3d3202c718a Mon Sep 17 00:00:00 2001 From: Hussein Bahdon <35459369+Dead-Section@users.noreply.github.com> Date: Sat, 4 Mar 2023 15:15:38 +0000 Subject: [PATCH 1/4] Hussein-Bahdon-london10-Doves --- 1-exercises/A-undefined/exercise.js | 5 +++++ 1-exercises/B-array-literals/exercise.js | 4 ++-- 1-exercises/C-array-get-set/exercise.js | 4 ++-- 1-exercises/C-array-get-set/exercises2.js | 5 +++++ 2-mandatory/3-stocks.js | 9 ++++++++- 5 files changed, 22 insertions(+), 5 deletions(-) diff --git a/1-exercises/A-undefined/exercise.js b/1-exercises/A-undefined/exercise.js index 0acfc78d..6fabbeed 100644 --- a/1-exercises/A-undefined/exercise.js +++ b/1-exercises/A-undefined/exercise.js @@ -13,15 +13,20 @@ let a; console.log(a); +// a doesnt have a any value; + // Example 2 function sayHello() { let message = "Hello"; } + let hello = sayHello(); console.log(hello); +//in line 25 hello is calling the function instead of setting it to hello; + // Example 3 function sayHelloToUser(user) { diff --git a/1-exercises/B-array-literals/exercise.js b/1-exercises/B-array-literals/exercise.js index 51eba5cc..9fa31994 100644 --- a/1-exercises/B-array-literals/exercise.js +++ b/1-exercises/B-array-literals/exercise.js @@ -4,8 +4,8 @@ Declare some variables assigned to arrays of values */ -let numbers = []; // add numbers from 1 to 10 into this array -let mentors; // Create an array with the names of the mentors: Daniel, Irina and Rares +let numbers = [1,2,3,4,5,6,7,8,9,10]; // add numbers from 1 to 10 into this array +let mentors = [" Daniel", "Irina", "Rares"] // Create an array with the names of the mentors: Daniel, Irina and Rares /* DO NOT EDIT BELOW THIS LINE diff --git a/1-exercises/C-array-get-set/exercise.js b/1-exercises/C-array-get-set/exercise.js index 5ca911d5..762e5173 100644 --- a/1-exercises/C-array-get-set/exercise.js +++ b/1-exercises/C-array-get-set/exercise.js @@ -5,11 +5,11 @@ */ function first(arr) { - return; // complete this statement + return arr[0] } function last(arr) { - return; // complete this statement + return arr[arr.length - 1]; } /* diff --git a/1-exercises/C-array-get-set/exercises2.js b/1-exercises/C-array-get-set/exercises2.js index 6b6b007a..4c0a5a30 100644 --- a/1-exercises/C-array-get-set/exercises2.js +++ b/1-exercises/C-array-get-set/exercises2.js @@ -8,13 +8,18 @@ let numbers = [1, 2, 3]; // Don't change this array literal declaration +numbers.push(4); +numbers[0] = 1; + /* DO NOT EDIT BELOW THIS LINE --------------------------- */ console.log(numbers); /* + EXPECTED RESULT --------------- [1, 2, 3, 4] + */ diff --git a/2-mandatory/3-stocks.js b/2-mandatory/3-stocks.js index 72d62f94..777c4484 100644 --- a/2-mandatory/3-stocks.js +++ b/2-mandatory/3-stocks.js @@ -34,7 +34,14 @@ const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [ Functions can help with this! */ function getAveragePrices(closingPricesForAllStocks) { - // TODO + + let [aapl, msft, amzn, googl, tsla] = stocks; + + CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS.forEach(a,b => { + return a + b / 5; + }); + + } /* From ac4cdb1aa00f433c14f90a53af148350582861ff Mon Sep 17 00:00:00 2001 From: hussein bahdon Date: Mon, 13 Mar 2023 22:30:16 +0000 Subject: [PATCH 2/4] Updated exercises --- .../E-while-loop-with-array/exercise.js | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/1-exercises/E-while-loop-with-array/exercise.js b/1-exercises/E-while-loop-with-array/exercise.js index d584cd75..fbd2a048 100644 --- a/1-exercises/E-while-loop-with-array/exercise.js +++ b/1-exercises/E-while-loop-with-array/exercise.js @@ -1,13 +1,15 @@ /* Loops can be useful when working with arrays. - In the below example, imagine we've defined an array holding the birthdays of your closest friends. - Use a while loop to search through the array until you find the first birthday in July, then return that birthday from the function. + In the below example, imagine we've defined an array holding + the birthdays of your closest friends. + Use a while loop to search through the array until you find the first birthday in July, + then return that birthday from the function. */ const BIRTHDAYS = [ - "January 7th", - "February 12th", - "April 3rd", + "January 7th", + "February 12th", + "April 3rd", "April 5th", "May 3rd", "July 11th", @@ -16,8 +18,22 @@ const BIRTHDAYS = [ "November 15th" ]; -function findFirstJulyBDay(birthdays) { - // TODO +function findFirstJulyBDay(parameter) { + + let currentIndex = 0; + + while (currentIndex < parameter.length){ + if (parameter[currentIndex].includes("July")) { + return parameter[currentIndex] + }else { + currentIndex++; + } + // console.log(parameter[currentIndex]) + } + return "no July here" + } + + console.log(findFirstJulyBDay(BIRTHDAYS)); // should output "July 11th" From ad6e95890bea3b5a1e7df93a889a6ea56787f3db Mon Sep 17 00:00:00 2001 From: Hussein Bahdon <35459369+H-BAHDON@users.noreply.github.com> Date: Wed, 5 Apr 2023 18:55:10 -0700 Subject: [PATCH 3/4] Update exercise.js --- 1-exercises/D-for-loop/exercise.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/1-exercises/D-for-loop/exercise.js b/1-exercises/D-for-loop/exercise.js index 081002b2..45df800a 100644 --- a/1-exercises/D-for-loop/exercise.js +++ b/1-exercises/D-for-loop/exercise.js @@ -28,6 +28,10 @@ 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: From dcf6c4e15e747b62f89a8589f0173fef82a54257 Mon Sep 17 00:00:00 2001 From: Hussein Bahdon <35459369+H-BAHDON@users.noreply.github.com> Date: Wed, 5 Apr 2023 19:30:01 -0700 Subject: [PATCH 4/4] london-10-Hussein-Bahdon-JS-1-Week3 --- 2-mandatory/1-weather-report.js | 13 ++++--- 2-mandatory/2-financial-times.js | 62 ++++++++++++++++++++++++++------ 2-mandatory/3-stocks.js | 56 ++++++++++++++++++++++------- 3 files changed, 104 insertions(+), 27 deletions(-) diff --git a/2-mandatory/1-weather-report.js b/2-mandatory/1-weather-report.js index dcc2bdb0..e297e8ac 100644 --- a/2-mandatory/1-weather-report.js +++ b/2-mandatory/1-weather-report.js @@ -10,11 +10,16 @@ For example, "The temperature in London is 10 degrees" - Hint: you can call the temperatureService function from your function */ - function getTemperatureReport(cities) { - // TODO -} - + const reports = []; + + for (let i = 0; i < cities.length; i++) { + const temperature = temperatureService(cities[i]); + reports.push(`The temperature in ${cities[i]} is ${temperature} degrees`); + } + + return reports; + } /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/2-mandatory/2-financial-times.js b/2-mandatory/2-financial-times.js index 2ce6fb73..0ec8e16b 100644 --- a/2-mandatory/2-financial-times.js +++ b/2-mandatory/2-financial-times.js @@ -1,11 +1,27 @@ /* - Imagine you are working on the Financial Times web site! They have a list of article titles stored in an array. + Imagine you are working on the Financial Times web site! + + They have a list of article titles stored in an array. + + The home page of the web site has a headline section, which only has space for article titles + which are 65 characters or less. - 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 + const container = [] + + for (let i = 0; i < allArticleTitles.length; i++) { + const titleContainter = allArticleTitles[i]; + if (titleContainter.length <= 65) { + container.push(titleContainter) + } + + + } + + return container + } /* @@ -14,25 +30,51 @@ function potentialHeadlines(allArticleTitles) { (you can assume words will always be seperated by a space) */ function titleWithFewestWords(allArticleTitles) { - // TODO -} - + let fewestWords = allArticleTitles[0]; + + for (let i = 1; i < allArticleTitles.length; i++) { + if (allArticleTitles[i].split(' ').length < fewestWords.split(' ').length) { + fewestWords = allArticleTitles[i]; + } + } + return fewestWords; + } /* The editor of the FT has realised that headlines which have numbers in them get more clicks! Implement the function below to return a new array containing all the headlines which contain a number. (Hint: remember that you can also loop through the characters of a string if you need to) */ function headlinesWithNumbers(allArticleTitles) { - // TODO -} + const container = []; + + for (let i = 0; i < allArticleTitles.length; i++) { + const title = allArticleTitles[i]; + for (let j = 0; j < title.length; j++) { + if (!isNaN(parseInt(title[j]))) { + container.push(title); + break; + } + } + } + + return container; + } /* The Financial Times wants to understand what the average number of characters in an article title is. Implement the function below to return this number - rounded to the nearest integer. */ function averageNumberOfCharacters(allArticleTitles) { - // TODO -} + let chars = 0; + + for (let i = 0; i < allArticleTitles.length; i++) { + chars += allArticleTitles[i].length; + } + + const averageChars = chars / allArticleTitles.length; + + return Math.round(averageChars); + } diff --git a/2-mandatory/3-stocks.js b/2-mandatory/3-stocks.js index 777c4484..9caa0e9d 100644 --- a/2-mandatory/3-stocks.js +++ b/2-mandatory/3-stocks.js @@ -34,15 +34,23 @@ const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [ Functions can help with this! */ function getAveragePrices(closingPricesForAllStocks) { - - let [aapl, msft, amzn, googl, tsla] = stocks; - - CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS.forEach(a,b => { - return a + b / 5; - }); - - -} + const result = []; + + for (let i = 0; i < closingPricesForAllStocks.length; i++) { + const stockPrices = closingPricesForAllStocks[i]; + let sum = 0; + + for (let j = 0; j < stockPrices.length; j++) { + sum += stockPrices[j]; + } + + const average = sum / stockPrices.length; + result.push(parseFloat(average.toFixed(2))); + } + + return result; + } + /* We also want to see what the change in price is from the first day to the last day for each stock. @@ -55,8 +63,19 @@ function getAveragePrices(closingPricesForAllStocks) { The price change value should be rounded to 2 decimal places, and should be a number (not a string) */ function getPriceChanges(closingPricesForAllStocks) { - // TODO -} + const priceChanges = []; + + for (let i = 0; i < closingPricesForAllStocks.length; i++) { + const stockPrices = closingPricesForAllStocks[i]; + const firstDayPrice = stockPrices[0]; + const lastDayPrice = stockPrices[stockPrices.length - 1]; + const priceChange = lastDayPrice - firstDayPrice; + priceChanges.push(parseFloat(priceChange.toFixed(2))); + } + + return priceChanges; + } + /* As part of a financial report, we want to see what the highest price was for each stock in the last 5 days. @@ -71,8 +90,19 @@ function getPriceChanges(closingPricesForAllStocks) { The price should be shown with exactly 2 decimal places. */ function highestPriceDescriptions(closingPricesForAllStocks, stocks) { - // TODO -} + const descriptions = []; + + for (let i = 0; i < stocks.length; i++) { + const stock = stocks[i]; + const closingPrices = closingPricesForAllStocks[i]; + const highestPrice = Math.max(...closingPrices).toFixed(2); + + descriptions.push(`The highest price of ${stock.toUpperCase()} in the last 5 days was ${highestPrice}`); + } + + return descriptions; + } + /* ======= TESTS - DO NOT MODIFY ===== */