diff --git a/README.md b/.md similarity index 100% rename from README.md rename to .md diff --git a/1-exercises/B-array-literals/exercise.js b/1-exercises/B-array-literals/exercise.js index 51eba5cc..d55dd053 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..8cac6689 100644 --- a/1-exercises/C-array-get-set/exercise.js +++ b/1-exercises/C-array-get-set/exercise.js @@ -5,13 +5,15 @@ */ function first(arr) { - return; // complete this statement + return arr [0];// complete this statement } function last(arr) { - return; // complete this statement + return arr[arr.length-1]; } + + /* DO NOT EDIT BELOW THIS LINE --------------------------- */ diff --git a/1-exercises/C-array-get-set/exercises2.js b/1-exercises/C-array-get-set/exercises2.js index 6b6b007a..acbec9b7 100644 --- a/1-exercises/C-array-get-set/exercises2.js +++ b/1-exercises/C-array-get-set/exercises2.js @@ -8,6 +8,9 @@ let numbers = [1, 2, 3]; // Don't change this array literal declaration +numbers.pushed = [4]; +numbers [0] = (1); + /* DO NOT EDIT BELOW THIS LINE --------------------------- */ diff --git a/1-exercises/D-for-loop/exercise.js b/1-exercises/D-for-loop/exercise.js index 081002b2..5a8d653a 100644 --- a/1-exercises/D-for-loop/exercise.js +++ b/1-exercises/D-for-loop/exercise.js @@ -27,6 +27,12 @@ const AGES = [ ]; // TODO - Write for loop code here +for (let i = 0; i < WRITERS.length; i++) { +console.log (`${WRITERS[i]} is ${WRITERS[i]} years old.`) +return getTemperatureReport; + +} + /* The output should look something like this: diff --git a/1-exercises/E-while-loop-with-array/exercise.js b/1-exercises/E-while-loop-with-array/exercise.js index d584cd75..b8d1b1b8 100644 --- a/1-exercises/E-while-loop-with-array/exercise.js +++ b/1-exercises/E-while-loop-with-array/exercise.js @@ -17,7 +17,14 @@ const BIRTHDAYS = [ ]; function findFirstJulyBDay(birthdays) { - // TODO -} + let i = 0; + while (i < birthdays.length) { + if (birthdays[i].includes("July")){ + return birthdays[i]; + } + i++ + } + + } console.log(findFirstJulyBDay(BIRTHDAYS)); // should output "July 11th" diff --git a/2-mandatory/1-weather-report.js b/2-mandatory/1-weather-report.js index dcc2bdb0..c9566f70 100644 --- a/2-mandatory/1-weather-report.js +++ b/2-mandatory/1-weather-report.js @@ -1,4 +1,5 @@ /* + Imagine we're making a weather app! We have a list of cities that the user wants to track. @@ -12,8 +13,19 @@ */ function getTemperatureReport(cities) { - // TODO + forecast = [] + for(city of cities){ + temperature = temperatureService(city); + information = `The temperature in ${city} is ${temperature} degrees`; + forecast.push(information); + } + return forecast; + + + + } + /* ======= TESTS - DO NOT MODIFY ===== */ diff --git a/2-mandatory/2-financial-times.js b/2-mandatory/2-financial-times.js index 2ce6fb73..4a85a5cc 100644 --- a/2-mandatory/2-financial-times.js +++ b/2-mandatory/2-financial-times.js @@ -5,37 +5,85 @@ Implement the function below, which will return a new array containing only article titles which will fit. */ function potentialHeadlines(allArticleTitles) { - // TODO + let titleCharacters = []; + + for (let title of allArticleTitles) { + + if (title.length<=65) { + titleCharacters.push(title); + + } + + } + return titleCharacters; } + + + /* The editor of the FT likes short headlines with only a few words! Implement the function below, which returns the title with the fewest words. (you can assume words will always be seperated by a space) */ function titleWithFewestWords(allArticleTitles) { - // TODO + + let shortHeadlines; + let fewestWords; + + for (let title of allArticleTitles) { + let numberOfWords = title.split(" ").length; + + if (fewestWords === undefined || numberOfWords < fewestWords) { + fewestWords = numberOfWords; + shortHeadlines = title; + } +} + return shortHeadlines; } + + + /* 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 +function findingNumber (str){ + return /[0-9]/.test(str); +} +function headlinesWithNumbers(allArticleTitles){ + let titleWithNumbers = []; + for (let headline of allArticleTitles) { + if (findingNumber(headline)=== true){ + titleWithNumbers.push(headline); + } + + } +return titleWithNumbers; + } + /* 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 total =0; + let numberOfArticles = allArticleTitles.length; + for (let headline of allArticleTitles){ + total = total + headline.length; + } + let averageNumberOfWords = Math.round(total/numberOfArticles); + + return averageNumberOfWords; } + /* ======= List of Articles - DO NOT MODIFY ===== */ const ARTICLE_TITLES = [ "Streaming wars drive media groups to spend more than $100bn on new content", diff --git a/2-mandatory/3-stocks.js b/2-mandatory/3-stocks.js index 72d62f94..f1b23545 100644 --- a/2-mandatory/3-stocks.js +++ b/2-mandatory/3-stocks.js @@ -34,8 +34,25 @@ const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [ Functions can help with this! */ function getAveragePrices(closingPricesForAllStocks) { - // TODO -} + let averagePrices = []; + + for(let types of closingPricesForAllStocks){ + let total = 0; + let average = 0; + for(let i of types) { + total +=i; + } + + average = Math.round(total/types.length *100)/100; + averagePrices.push(average); + + + } + return averagePrices; + + + } + /* We also want to see what the change in price is from the first day to the last day for each stock. @@ -48,7 +65,14 @@ 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 + let changesInPrice = []; + for (let types of closingPricesForAllStocks) { + let firstDayPrice = types[0]; + let lastDayPrice = types[types.length-1]; + + changesInPrice.push(Math.round((lastDayPrice - firstDayPrice)*100)/100); + } + return changesInPrice; } /* @@ -64,7 +88,16 @@ function getPriceChanges(closingPricesForAllStocks) { The price should be shown with exactly 2 decimal places. */ function highestPriceDescriptions(closingPricesForAllStocks, stocks) { - // TODO + let financialReport = []; + let highestPrice = 0; + let stock = 0; + for (let types of closingPricesForAllStocks) { + highestPrice = Math.max(...types).toFixed(2); + financialReport.push (`The highest price of ${stocks[stock].toUpperCase()} in the last 5 days was ${highestPrice}`); + stock++; + + } + return financialReport; }