diff --git a/1-exercises/A-undefined/exercise.js b/1-exercises/A-undefined/exercise.js index 0acfc78d..076fc9f6 100644 --- a/1-exercises/A-undefined/exercise.js +++ b/1-exercises/A-undefined/exercise.js @@ -11,12 +11,12 @@ // Example 1 let a; -console.log(a); +console.log(a); //it will be undefined because it does not have any value // Example 2 function sayHello() { - let message = "Hello"; + let message = "Hello"; //hello is not a string in console.log, so the program reads it as variable, but "hello" doesn't exist. } let hello = sayHello(); @@ -28,9 +28,10 @@ function sayHelloToUser(user) { console.log(`Hello ${user}`); } -sayHelloToUser(); +sayHelloToUser(); //when calling function we don't pass any value for parameter user + // Example 4 let arr = [1,2,3]; -console.log(arr[3]); +console.log(arr[3]); //element in arr with index 3 doesn't exist. There only 0, 1, 2. diff --git a/1-exercises/B-array-literals/exercise.js b/1-exercises/B-array-literals/exercise.js index 51eba5cc..e0034349 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", "Irina"]// 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..672aa87e 100644 --- a/1-exercises/C-array-get-set/exercise.js +++ b/1-exercises/C-array-get-set/exercise.js @@ -4,12 +4,12 @@ Complete the functions below to get the first and last values from the array */ -function first(arr) { - return; // complete this statement +function first( numbers) { + return [0] [2]; // complete this statement } -function last(arr) { - return; // complete this statement +function last(names) { + return[3]; // complete this statement } /* diff --git a/1-exercises/C-array-get-set/exercises2.js b/1-exercises/C-array-get-set/exercises2.js index 6b6b007a..caf5aaff 100644 --- a/1-exercises/C-array-get-set/exercises2.js +++ b/1-exercises/C-array-get-set/exercises2.js @@ -6,8 +6,8 @@ - change the first value in the array to the number 1 */ -let numbers = [1, 2, 3]; // Don't change this array literal declaration - +let numbers = [2, 3, 4]; // Don't change this array literal declaration + 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..7c31cd44 100644 --- a/1-exercises/D-for-loop/exercise.js +++ b/1-exercises/D-for-loop/exercise.js @@ -37,3 +37,8 @@ Jane Austen is 41 years old Bell Hooks is 63 years old Yukiko Motoya is 49 years old */ +const AGES = [59, 40, 41, 63, 49]; + +for (let i = 0; i < WRITERS.length; i++) { + console.log(WRITERS[i] + " is " + AGES[i] + " years old"); +} \ No newline at end of file diff --git a/1-exercises/E-while-loop-with-array/exercise.js b/1-exercises/E-while-loop-with-array/exercise.js index d584cd75..97a31ee7 100644 --- a/1-exercises/E-while-loop-with-array/exercise.js +++ b/1-exercises/E-while-loop-with-array/exercise.js @@ -15,9 +15,19 @@ const BIRTHDAYS = [ "September 28th", "November 15th" ]; +//let count = 0; -function findFirstJulyBDay(birthdays) { +function findFirstJulyBDay(parameter) { // TODO -} + //let i = 0; + let currentIndex = 0; + while(currentIndex < parameter.length){ + if(parameter[currentIndex].includes('July')){ + return parameter[currentIndex]; + } + console.log(parameter[currentIndex]) + currentIndex++; + } -console.log(findFirstJulyBDay(BIRTHDAYS)); // should output "July 11th" + // should output "July 11th" +} diff --git a/2-mandatory/1-weather-report.js b/2-mandatory/1-weather-report.js index dcc2bdb0..4d13ce82 100644 --- a/2-mandatory/1-weather-report.js +++ b/2-mandatory/1-weather-report.js @@ -13,9 +13,25 @@ function getTemperatureReport(cities) { // TODO -} - + let arr = []; + let degree = 0; + let cityDegree = ""; + for (let i = 0; i < cities.length; i++) { + degree = temperatureService(cities[i]); + + arr.push(cityDegree); + } + return arr; +} let arr = []; + let degree = 0; + let cityDegree = ""; + for (let i = 0; i < cities.length; i++) { + degree = temperatureService(cities[i]); + cityDegree = `The temperature in ${cities[i]} is ${degree} degrees`; + arr.push(cityDegree); + } + return arr /* ======= TESTS - DO NOT MODIFY ===== */ function temperatureService(city) { diff --git a/2-mandatory/2-financial-times.js b/2-mandatory/2-financial-times.js index 2ce6fb73..8e972be7 100644 --- a/2-mandatory/2-financial-times.js +++ b/2-mandatory/2-financial-times.js @@ -6,6 +6,17 @@ */ function potentialHeadlines(allArticleTitles) { // TODO + function potentialHeadlines(allArticleTitles) { + // TODO + let shortArticles = []; + for (let article of allArticleTitles) { + if (article.length <= 65) { + shortArticles.push(article); + } + } + return shortArticles; +} + } /* @@ -15,6 +26,14 @@ function potentialHeadlines(allArticleTitles) { */ function titleWithFewestWords(allArticleTitles) { // TODO + const myArray = []; + for (let article of allArticleTitles) { + myArray.push(article.split(" ")); + } + let result = myArray.reduce(function (a,b) { + return a.length <= b.length ? a : b; + }); + return allArticleTitles[myArray.indexOf(result)]; } /* @@ -24,18 +43,40 @@ function titleWithFewestWords(allArticleTitles) { */ function headlinesWithNumbers(allArticleTitles) { // TODO + let countArray = []; + for (article of allArticleTitles) { + countArray.push(article.length); + } + let sum = 0; + for (let i = 0; i < countArray.length; i++) { + sum += countArray[i]; + } + return Math.round(sum / countArray.length); } + + + /* 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 countArray = []; + for (article of allArticleTitles) { + countArray.push(article.length); + } + let sum = 0; + for (let i = 0; i < countArray.length; i++) { + sum += countArray[i]; + } + return Math.round(sum / countArray.length); } + /* ======= 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..d0e61cf7 100644 --- a/2-mandatory/3-stocks.js +++ b/2-mandatory/3-stocks.js @@ -35,8 +35,16 @@ const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [ */ function getAveragePrices(closingPricesForAllStocks) { // TODO + let averageOfWeek = []; + //looping through array of arrays and calling findAveragePrice method on each array + for (let averageOfWeek of closingPricesForAllStocks) { + averageOfWeek.push(findAveragePrice(averageOfWeek)); + } + return averageOfWeek; } + + /* We also want to see what the change in price is from the first day to the last day for each stock. Implement the below function, which @@ -49,6 +57,13 @@ function getAveragePrices(closingPricesForAllStocks) { */ function getPriceChanges(closingPricesForAllStocks) { // TODO + let result =[]; + + for( let i = 0; i< closingPricesForAllStocks.length; i++) { + let diff =0; + diff = closingPricesForAllStocks[i][4] - closingPricesForAllStocks[i][0]; + result.push(parseFloat(diff.toFixed(2))); + } } /* @@ -65,6 +80,19 @@ function getPriceChanges(closingPricesForAllStocks) { */ function highestPriceDescriptions(closingPricesForAllStocks, stocks) { // TODO + + let arr = []; + for (let i = 0; i < closingPricesForAllStocks.length; i++) { + arr.push( + `The highest price of ${stocks[ + i + ].toUpperCase()} in the last 5 days was ${Math.max( + ...closingPricesForAllStocks[i] + ).toFixed(2)}` + ); + } + return arr; + }