From c4515ee3ab15d222a64aabb2862b0891ca81d982 Mon Sep 17 00:00:00 2001 From: batuncer Date: Tue, 7 Mar 2023 17:16:40 +0000 Subject: [PATCH 1/4] homework is done except stocks.js --- 2-mandatory/1-weather-report.js | 15 +++++++++++++++ 2-mandatory/2-financial-times.js | 29 +++++++++++++++++++++++++++++ 2-mandatory/3-stocks.js | 24 +++++++++++++++++++++--- 3 files changed, 65 insertions(+), 3 deletions(-) diff --git a/2-mandatory/1-weather-report.js b/2-mandatory/1-weather-report.js index dcc2bdb0..329497c4 100644 --- a/2-mandatory/1-weather-report.js +++ b/2-mandatory/1-weather-report.js @@ -13,6 +13,21 @@ function getTemperatureReport(cities) { // TODO + let temperatureReport = []; // First, we initialize an empty array temperatureReport to hold the statements about the temperature of each city. + + // Next, we use a for loop to loop through each city in the cities array. + for (let i; i title.length <= 65); + } /* @@ -15,6 +18,13 @@ function potentialHeadlines(allArticleTitles) { */ function titleWithFewestWords(allArticleTitles) { // TODO + let fewestWordsTitle = allArticleTitles[0]; + for (let i = 1; i < allArticleTitles.length; i++) { + if (allArticleTitles[i].split(" ").length < fewestWordsTitle.split(" ").length) { + fewestWordsTitle = allArticleTitles[i]; + } + } + return fewestWordsTitle; } /* @@ -24,6 +34,17 @@ function titleWithFewestWords(allArticleTitles) { */ function headlinesWithNumbers(allArticleTitles) { // TODO + let headlinesWithNums = []; + //Return an array containing all the headlines which contain a number + for (let i = 0; i < allArticleTitles.length; i++) { + for (let j = 0; j < allArticleTitles[i].length; j++) { + if (!isNaN(parseInt(allArticleTitles[i][j]))) { + headlinesWithNums.push(allArticleTitles[i]); + break; + } + } + } + return headlinesWithNums; } /* @@ -32,6 +53,14 @@ function headlinesWithNumbers(allArticleTitles) { */ function averageNumberOfCharacters(allArticleTitles) { // TODO + // return the average number of characters in an article title + + let totalChars = 0; + for (let i = 0; i < allArticleTitles.length; i++) { + totalChars += allArticleTitles[i].length; + } + let avgChars = Math.round(totalChars / allArticleTitles.length); + return avgChars; } diff --git a/2-mandatory/3-stocks.js b/2-mandatory/3-stocks.js index 72d62f94..8e8c9d2b 100644 --- a/2-mandatory/3-stocks.js +++ b/2-mandatory/3-stocks.js @@ -35,8 +35,25 @@ const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [ */ function getAveragePrices(closingPricesForAllStocks) { // TODO + + let output=[] + + for (let i=0 ; i< closingPricesForAllStocks.lenght; i++){ + const price = closingPricesForAllStocks[i]; + const totalPrice= price.reduce(function (a,b){ + return a+b; + }, 0) + const avarage = totalPrice / price.lenght; + const avarageFixed=avarage.toFixed(2) + + output.push(avarageFixed) } + +return output; + +} +console.log(getAveragePrices(CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS)) /* 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 @@ -48,10 +65,10 @@ 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 + } -/* +/* As part of a financial report, we want to see what the highest price was for each stock in the last 5 days. Implement the below function, which - Takes 2 parameters: @@ -65,6 +82,7 @@ function getPriceChanges(closingPricesForAllStocks) { */ function highestPriceDescriptions(closingPricesForAllStocks, stocks) { // TODO + } @@ -91,4 +109,4 @@ test("should return a description of the highest price for each stock", () => { "The highest price of TSLA in the last 5 days was 1101.30" ] ); -}); +}); From 4ffb954475d43603ac0f1c221f885482fbcab75c Mon Sep 17 00:00:00 2001 From: batuncer Date: Tue, 7 Mar 2023 17:19:17 +0000 Subject: [PATCH 2/4] excercises are done --- 1-exercises/A-undefined/exercise.js | 6 +++++- 1-exercises/B-array-literals/exercise.js | 6 +++++- 1-exercises/C-array-get-set/exercise.js | 8 ++++++-- 1-exercises/C-array-get-set/exercises2.js | 2 +- 1-exercises/D-for-loop/exercise.js | 9 +++++++-- 1-exercises/E-while-loop-with-array/exercise.js | 11 +++++++++-- 6 files changed, 33 insertions(+), 9 deletions(-) diff --git a/1-exercises/A-undefined/exercise.js b/1-exercises/A-undefined/exercise.js index 0acfc78d..f6a94a66 100644 --- a/1-exercises/A-undefined/exercise.js +++ b/1-exercises/A-undefined/exercise.js @@ -9,12 +9,14 @@ For each example, can you explain why we are seeing undefined? */ -// Example 1 +// Example 1 +//we are declaring a variable "a" without initializing it. When we try to log the value of "a" to the console, we get undefined because we haven't assigned a value to it yet. let a; console.log(a); // Example 2 +//we have a function called "sayHello" which initializes a local variable called "message" and doesn't return anything. When we call "sayHello" and assign the result to the "hello" variable, the value of "hello" becomes undefined because the function doesn't return anything. function sayHello() { let message = "Hello"; } @@ -24,6 +26,7 @@ console.log(hello); // Example 3 +//we have a function called "sayHelloToUser" that expects a parameter called "user". When we call "sayHelloToUser" without passing any arguments, the "user" parameter is undefined, which causes the function to log "Hello undefined" to the console. function sayHelloToUser(user) { console.log(`Hello ${user}`); } @@ -32,5 +35,6 @@ sayHelloToUser(); // Example 4 +// we have an array called "arr" with three elements. When we try to access the fourth element using the index 3, we get undefined because the array doesn't have a fourth element. In JavaScript, when you try to access an index that doesn't exist in an array, the value returned is undefined. let arr = [1,2,3]; console.log(arr[3]); diff --git a/1-exercises/B-array-literals/exercise.js b/1-exercises/B-array-literals/exercise.js index 51eba5cc..a8bbd45f 100644 --- a/1-exercises/B-array-literals/exercise.js +++ b/1-exercises/B-array-literals/exercise.js @@ -5,8 +5,12 @@ */ 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 +for (let i = 1; i<=10 ; i++){ + numbers.push(i); +} +let mentors; // Create an array with the names of the mentors: Daniel, Irina and Rares +mentors = ['Daniel', 'Irina', '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..b7d898cb 100644 --- a/1-exercises/C-array-get-set/exercise.js +++ b/1-exercises/C-array-get-set/exercise.js @@ -5,13 +5,17 @@ */ function first(arr) { - return; // complete this statement + + return arr[0]; } 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..d2f3d963 100644 --- a/1-exercises/C-array-get-set/exercises2.js +++ b/1-exercises/C-array-get-set/exercises2.js @@ -7,7 +7,7 @@ */ let numbers = [1, 2, 3]; // Don't change this array literal declaration - +numbers.push(4) /* 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..e4f3a97b 100644 --- a/1-exercises/D-for-loop/exercise.js +++ b/1-exercises/D-for-loop/exercise.js @@ -28,8 +28,13 @@ const AGES = [ // TODO - Write for loop code here -/* -The output should look something like this: +for(let i ; i Date: Tue, 14 Mar 2023 11:51:27 +0000 Subject: [PATCH 3/4] editted errors --- 1-exercises/A-undefined/exercise.js | 6 ++++-- 1-exercises/E-while-loop-with-array/exercise.js | 12 ++++++------ 3-extra/3-fibonacci.js | 15 +++++++++++++-- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/1-exercises/A-undefined/exercise.js b/1-exercises/A-undefined/exercise.js index f6a94a66..d19c3708 100644 --- a/1-exercises/A-undefined/exercise.js +++ b/1-exercises/A-undefined/exercise.js @@ -11,7 +11,7 @@ // Example 1 //we are declaring a variable "a" without initializing it. When we try to log the value of "a" to the console, we get undefined because we haven't assigned a value to it yet. -let a; +let a= 3 console.log(a); @@ -19,6 +19,7 @@ console.log(a); //we have a function called "sayHello" which initializes a local variable called "message" and doesn't return anything. When we call "sayHello" and assign the result to the "hello" variable, the value of "hello" becomes undefined because the function doesn't return anything. function sayHello() { let message = "Hello"; + return message } let hello = sayHello(); @@ -31,10 +32,11 @@ function sayHelloToUser(user) { console.log(`Hello ${user}`); } -sayHelloToUser(); +sayHelloToUser('baki'); // Example 4 // we have an array called "arr" with three elements. When we try to access the fourth element using the index 3, we get undefined because the array doesn't have a fourth element. In JavaScript, when you try to access an index that doesn't exist in an array, the value returned is undefined. let arr = [1,2,3]; +arr.push(4) console.log(arr[3]); diff --git a/1-exercises/E-while-loop-with-array/exercise.js b/1-exercises/E-while-loop-with-array/exercise.js index a5073421..cd60cdcb 100644 --- a/1-exercises/E-while-loop-with-array/exercise.js +++ b/1-exercises/E-while-loop-with-array/exercise.js @@ -16,14 +16,14 @@ const BIRTHDAYS = [ "November 15th" ]; -function findFirstJulyBDay { - let i=0; - while (i { expect(generateFibonacciSequence(10)).toEqual( [0, 1, 1, 2, 3, 5, 8, 13, 21, 34] @@ -34,4 +45,4 @@ test("should return the first 15 numbers in the Fibonacci Sequence", () => { expect(generateFibonacciSequence(15)).toEqual( [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377] ); -}); \ No newline at end of file +});*/ \ No newline at end of file From 881a6112caa924f8565283a22743031eef59f3c9 Mon Sep 17 00:00:00 2001 From: batuncer Date: Sat, 18 Mar 2023 14:43:02 +0000 Subject: [PATCH 4/4] erros are editted --- 2-mandatory/1-weather-report.js | 9 ++- 2-mandatory/3-stocks.js | 103 +++++++++++++++++++------------- 2 files changed, 66 insertions(+), 46 deletions(-) diff --git a/2-mandatory/1-weather-report.js b/2-mandatory/1-weather-report.js index 329497c4..3a22c015 100644 --- a/2-mandatory/1-weather-report.js +++ b/2-mandatory/1-weather-report.js @@ -16,15 +16,18 @@ function getTemperatureReport(cities) { let temperatureReport = []; // First, we initialize an empty array temperatureReport to hold the statements about the temperature of each city. // Next, we use a for loop to loop through each city in the cities array. - for (let i; i { - expect(getAveragePrices(CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS)).toEqual( - [176.89, 335.66, 3405.66, 2929.22, 1041.93] - ); + expect(getAveragePrices(CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS)).toEqual([ + 176.89, 335.66, 3405.66, 2929.22, 1041.93, + ]); }); test("should return the price change for each stock", () => { - expect(getPriceChanges(CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS)).toEqual( - [-6.2, -13.4, 23.9, -82.43, -162.77] - ); + expect(getPriceChanges(CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS)).toEqual([ + -6.2, -13.4, 23.9, -82.43, -162.77, + ]); }); test("should return a description of the highest price for each stock", () => { - expect(highestPriceDescriptions(CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS, STOCKS)).toEqual( - [ - "The highest price of AAPL in the last 5 days was 180.33", - "The highest price of MSFT in the last 5 days was 342.45", - "The highest price of AMZN in the last 5 days was 3421.37", - "The highest price of GOOGL in the last 5 days was 2958.13", - "The highest price of TSLA in the last 5 days was 1101.30" - ] - ); -}); + expect( + highestPriceDescriptions(CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS, STOCKS) + ).toEqual([ + "The highest price of AAPL in the last 5 days was 180.33", + "The highest price of MSFT in the last 5 days was 342.45", + "The highest price of AMZN in the last 5 days was 3421.37", + "The highest price of GOOGL in the last 5 days was 2958.13", + "The highest price of TSLA in the last 5 days was 1101.30", + ]); +});