From 06aa6e4ca3095e547b5e5a68313cdc8c9507e31f Mon Sep 17 00:00:00 2001 From: Delnia Alipour Date: Wed, 1 Mar 2023 17:21:49 +0000 Subject: [PATCH 1/4] 1-exercises --- 1-exercises/A-undefined/exercise.js | 8 ++++---- 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 | 3 ++- 1-exercises/D-for-loop/exercise.js | 3 +++ 1-exercises/E-while-loop-with-array/exercise.js | 11 ++++++++--- 6 files changed, 21 insertions(+), 12 deletions(-) diff --git a/1-exercises/A-undefined/exercise.js b/1-exercises/A-undefined/exercise.js index 0acfc78d..cd4bf55a 100644 --- a/1-exercises/A-undefined/exercise.js +++ b/1-exercises/A-undefined/exercise.js @@ -9,12 +9,12 @@ For each example, can you explain why we are seeing undefined? */ -// Example 1 +// a does'nt have any value. let a; console.log(a); -// Example 2 +// The function sayHello doesn't return anything. function sayHello() { let message = "Hello"; } @@ -23,7 +23,7 @@ let hello = sayHello(); console.log(hello); -// Example 3 +// The function is recalled with no parameter. function sayHelloToUser(user) { console.log(`Hello ${user}`); } @@ -31,6 +31,6 @@ function sayHelloToUser(user) { sayHelloToUser(); -// Example 4 +// The array has no 4th element (index is counted from 0). 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..44e2323c 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..6736a5ee 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]; // complete this statement } function last(arr) { - return; // complete this statement + return arr[arr.length-1]; // 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..f6526b5a 100644 --- a/1-exercises/C-array-get-set/exercises2.js +++ b/1-exercises/C-array-get-set/exercises2.js @@ -7,7 +7,8 @@ */ let numbers = [1, 2, 3]; // Don't change this array literal declaration - +numbers[numbers.length]=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..f23a7f75 100644 --- a/1-exercises/D-for-loop/exercise.js +++ b/1-exercises/D-for-loop/exercise.js @@ -27,6 +27,9 @@ const AGES = [ ]; // TODO - Write for loop code here +for(let i =0; i Date: Thu, 2 Mar 2023 20:20:17 +0000 Subject: [PATCH 2/4] 2- Mandatory --- 2-mandatory/1-weather-report.js | 5 ++++ 2-mandatory/2-financial-times.js | 41 ++++++++++++++++++++++++----- 2-mandatory/3-stocks.js | 44 +++++++++++++++++++++++++++++--- 3 files changed, 80 insertions(+), 10 deletions(-) diff --git a/2-mandatory/1-weather-report.js b/2-mandatory/1-weather-report.js index dcc2bdb0..0a917868 100644 --- a/2-mandatory/1-weather-report.js +++ b/2-mandatory/1-weather-report.js @@ -13,6 +13,11 @@ function getTemperatureReport(cities) { // TODO + const temperatureReport=[]; + for( let i=0; iallArticleTitles[i].length){ + fewestWords=allArticleTitles[i]; + } + } + return fewestWords; +} +// function getWordsCount(allArticleTitles){ +// return allArticleTitles.split(" ").length; +// } /* - The editor of the FT has realised that headlines which have numbers in them get more clicks! + The editor of the FT has realized 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 containNumbers=[]; + for(let i =0; i Date: Thu, 2 Mar 2023 20:22:41 +0000 Subject: [PATCH 3/4] 3- extra (except array -of -objects) --- 3-extra/1-radio-stations.js | 20 ++++++++++++++++++++ 3-extra/3-fibonacci.js | 8 ++++++++ 2 files changed, 28 insertions(+) diff --git a/3-extra/1-radio-stations.js b/3-extra/1-radio-stations.js index 577076e9..e4e08b96 100644 --- a/3-extra/1-radio-stations.js +++ b/3-extra/1-radio-stations.js @@ -14,6 +14,16 @@ */ // `getAllFrequencies` goes here +function getAllFrequencies(){ + const frequencies=[]; + let k=87; + for( let i=0; i<22;i++){ + frequencies.push(k); + k++; + } + return frequencies; + +} /** * Next, let's write a function that gives us only the frequencies that are radio stations. @@ -25,7 +35,17 @@ * - Return only the frequencies that are radio stations. */ // `getStations` goes here +function getStations(){ + const stations=[]; + const availableFreq= getAllFrequencies(); + for(let i =0; i Date: Sat, 4 Mar 2023 12:13:19 +0000 Subject: [PATCH 4/4] Array-of-objects done! --- 3-extra/2-array-of-objects.js | 53 +++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/3-extra/2-array-of-objects.js b/3-extra/2-array-of-objects.js index ee57960f..bd40c34a 100644 --- a/3-extra/2-array-of-objects.js +++ b/3-extra/2-array-of-objects.js @@ -11,6 +11,58 @@ */ function getHighestRatedInEachGenre(books) { + let booksLength= books.length; + let children=[]; + let fiction=[]; + let cooking=[]; + let resultArr=[]; + for (let i=0;i childrenRate){ + childrenRate = children[j].rating; + childrenTitle = children[j].title; + } + + } + + + let nonfictionRate = 0 ; + let nonfictionTitle = ""; + for (let j=0 ;j nonfictionRate){ + nonfictionRate = fiction[j].rating; + nonfictionTitle = fiction[j].title; + } + + } + + + let cookingRate = 0 ; + let cookingTitle = ""; + for (let j=0 ;j cookingRate){ + cookingRate = cooking[j].rating; + cookingTitle = cooking[j].title; + } + + } + resultArr.push(nonfictionTitle); + resultArr.push(childrenTitle); + resultArr.push(cookingTitle); + return resultArr; + // TODO } @@ -68,6 +120,7 @@ const BOOKS = [ rating: 4.85 }, ] +// console.log(getHighestRatedInEachGenre(BOOKS)); /* ======= TESTS - DO NOT MODIFY ===== */