From 2dc0ef69394b7839ecca1e79f9f46fc3dcf95e36 Mon Sep 17 00:00:00 2001 From: KamNik0044 <105980197+KamNik0044@users.noreply.github.com> Date: Thu, 22 Sep 2022 20:32:31 +0100 Subject: [PATCH] Exercises&MandatoriesDone --- 1-exercises/A-undefined/exercise.js | 8 ++-- 1-exercises/B-while-loop/exercise.js | 8 ++++ .../C-while-loop-with-array/exercise.js | 8 ++++ 1-exercises/D-do-while/exercise.js | 14 ++++++ 1-exercises/E-for-loop/exercise1.js | 1 + 1-exercises/E-for-loop/exercise2.js | 3 ++ 1-exercises/F-for-of-loop/exercise.js | 7 ++- 2-mandatory/1-weather-report.js | 6 +++ 2-mandatory/2-retrying-random-numbers.js | 7 +++ 2-mandatory/3-financial-times.js | 48 +++++++++++++++++++ 2-mandatory/4-stocks.js | 22 ++++++++- 11 files changed, 127 insertions(+), 5 deletions(-) diff --git a/1-exercises/A-undefined/exercise.js b/1-exercises/A-undefined/exercise.js index 0acfc78d..9c62dba6 100644 --- a/1-exercises/A-undefined/exercise.js +++ b/1-exercises/A-undefined/exercise.js @@ -12,7 +12,7 @@ // Example 1 let a; console.log(a); - +// This is because no value is assigned to the variable "a". So attempting to print its value would print "undefined" // Example 2 function sayHello() { @@ -21,7 +21,8 @@ function sayHello() { let hello = sayHello(); console.log(hello); - +// The function "sayHello()" does not have any return value. Therefore, the value of the function when +// invoked would be "undefined", which is saved into hello. // Example 3 function sayHelloToUser(user) { @@ -29,8 +30,9 @@ function sayHelloToUser(user) { } sayHelloToUser(); - +// Here, we are only calling the function without entering the input to the function. // Example 4 let arr = [1,2,3]; console.log(arr[3]); +// There is no element in index 3 of the array "arr". Out of bound indexing of the array leads to undefined value. \ No newline at end of file diff --git a/1-exercises/B-while-loop/exercise.js b/1-exercises/B-while-loop/exercise.js index b459888f..5749b750 100644 --- a/1-exercises/B-while-loop/exercise.js +++ b/1-exercises/B-while-loop/exercise.js @@ -7,6 +7,14 @@ function evenNumbers(n) { // TODO + let result = ""; + let i = 0 + while(i < n){ + result += `${2*i},`; + i++; + } + return result.slice(0, -1); + } evenNumbers(3); // should output 0,2,4 diff --git a/1-exercises/C-while-loop-with-array/exercise.js b/1-exercises/C-while-loop-with-array/exercise.js index d584cd75..3972f0c8 100644 --- a/1-exercises/C-while-loop-with-array/exercise.js +++ b/1-exercises/C-while-loop-with-array/exercise.js @@ -18,6 +18,14 @@ const BIRTHDAYS = [ function findFirstJulyBDay(birthdays) { // TODO + let ind = 0; + for (let i = 0; i < birthdays.length; i++){ + if (birthdays[i].includes("July")){ + ind = i; + break; + } + } + return birthdays[ind]; } 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..d3fe7a52 100644 --- a/1-exercises/D-do-while/exercise.js +++ b/1-exercises/D-do-while/exercise.js @@ -8,6 +8,20 @@ function evenNumbersSum(n) { // TODO + let i = 0; + let evenArray = []; + let result = 0; + do { + evenArray.push(result); + result += 2; + i += 1; + } while (i < n); + let val = 0; + // console.log(evenArray); + for (let j=0; j prices.sort((a, b) => b - a)); + return sortedClosingPrices.map((value, index) => { + return `The highest price of ${stocks[index].toUpperCase()} in the last 5 days was ${(value[0].toFixed(2))}`; + }) }