From 946f53893e0c356a8b269094dcb37cf6feb5c813 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 5 Mar 2023 11:42:08 +0000 Subject: [PATCH 1/3] 1-exercises fixed --- 1-exercises/A-undefined/exercise.js | 13 ++++++++----- 1-exercises/B-array-literals/exercise.js | 8 ++++---- 1-exercises/C-array-get-set/exercise.js | 8 ++++---- 1-exercises/C-array-get-set/exercises2.js | 6 +++--- 1-exercises/D-for-loop/exercise.js | 4 +++- 1-exercises/E-while-loop-with-array/exercise.js | 15 +++++++++++++-- 6 files changed, 35 insertions(+), 19 deletions(-) diff --git a/1-exercises/A-undefined/exercise.js b/1-exercises/A-undefined/exercise.js index 0acfc78d..348a0081 100644 --- a/1-exercises/A-undefined/exercise.js +++ b/1-exercises/A-undefined/exercise.js @@ -1,7 +1,7 @@ /* By now, you would have already seen "undefined", either in an error message or being output from your program. But what does it mean? undefined represents the absence of a value. - + In some cases, undefined will be used by a programmer intentionally, and they will write code to handle it. But usually, when you see undefined - it means something has gone wrong! @@ -12,25 +12,28 @@ // Example 1 let a; console.log(a); - +/*we saw undefine output because we declared variable and + we didn't assign any value ,that's mean nothing to display.*/ // Example 2 function sayHello() { let message = "Hello"; -} +} let hello = sayHello(); console.log(hello); - +/* we saw undefine output because function doesn't return or output anything*/ // Example 3 function sayHelloToUser(user) { console.log(`Hello ${user}`); } - sayHelloToUser(); +/* we saw undefine output because we didn't assign any value for the variable 'user' +that's mean the variable is empty*/ // Example 4 let arr = [1,2,3]; console.log(arr[3]); +/*we saw undefine we don't have index[3] in the array */ \ No newline at end of file diff --git a/1-exercises/B-array-literals/exercise.js b/1-exercises/B-array-literals/exercise.js index 51eba5cc..1b457b0c 100644 --- a/1-exercises/B-array-literals/exercise.js +++ b/1-exercises/B-array-literals/exercise.js @@ -4,16 +4,16 @@ 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 --------------------------- */ console.log(numbers); console.log(mentors); -/* +/* EXPECTED RESULT --------------- [1,2,3,4,5,6,7,8,9,10] diff --git a/1-exercises/C-array-get-set/exercise.js b/1-exercises/C-array-get-set/exercise.js index 5ca911d5..e5003bcf 100644 --- a/1-exercises/C-array-get-set/exercise.js +++ b/1-exercises/C-array-get-set/exercise.js @@ -5,14 +5,14 @@ */ 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 } -/* +/* DO NOT EDIT BELOW THIS LINE --------------------------- */ let numbers = [1, 2, 3]; @@ -22,7 +22,7 @@ console.log(first(numbers)); console.log(last(numbers)); console.log(last(names)); -/* +/* EXPECTED RESULT --------------- 1 diff --git a/1-exercises/C-array-get-set/exercises2.js b/1-exercises/C-array-get-set/exercises2.js index 6b6b007a..aca3ba5d 100644 --- a/1-exercises/C-array-get-set/exercises2.js +++ b/1-exercises/C-array-get-set/exercises2.js @@ -7,13 +7,13 @@ */ let numbers = [1, 2, 3]; // Don't change this array literal declaration - -/* + numbers.push(4) +/* DO NOT EDIT BELOW THIS LINE --------------------------- */ console.log(numbers); -/* +/* EXPECTED RESULT --------------- [1, 2, 3, 4] diff --git a/1-exercises/D-for-loop/exercise.js b/1-exercises/D-for-loop/exercise.js index 081002b2..96b9ea28 100644 --- a/1-exercises/D-for-loop/exercise.js +++ b/1-exercises/D-for-loop/exercise.js @@ -27,7 +27,9 @@ const AGES = [ ]; // TODO - Write for loop code here - +for(let i=0 ;i Date: Sun, 5 Mar 2023 11:44:29 +0000 Subject: [PATCH 2/3] 2-mandatory fixed --- 2-mandatory/1-weather-report.js | 15 ++++++++--- 2-mandatory/2-financial-times.js | 39 +++++++++++++++++++++++++-- 2-mandatory/3-stocks.js | 46 +++++++++++++++++++++++++++++--- 3 files changed, 92 insertions(+), 8 deletions(-) diff --git a/2-mandatory/1-weather-report.js b/2-mandatory/1-weather-report.js index dcc2bdb0..fce2cb34 100644 --- a/2-mandatory/1-weather-report.js +++ b/2-mandatory/1-weather-report.js @@ -1,6 +1,6 @@ /* Imagine we're making a weather app! - + We have a list of cities that the user wants to track. We also already have a temperatureService function which will take a city as a parameter and return a temparature. @@ -12,8 +12,17 @@ */ function getTemperatureReport(cities) { + let report = []; + for (let i = 0; i < cities.length; i++) { + let temperatureReport = temperatureService(cities[i]); + report.push(`The temperature in ${cities[i]} is ${temperatureReport} degrees`); + } + return report; + + } + // TODO -} + /* ======= TESTS - DO NOT MODIFY ===== */ @@ -28,7 +37,7 @@ function temperatureService(city) { temparatureMap.set('Mumbai', 29); temparatureMap.set('São Paulo', 23); temparatureMap.set('Lagos', 33); - + return temparatureMap.get(city); } diff --git a/2-mandatory/2-financial-times.js b/2-mandatory/2-financial-times.js index 2ce6fb73..978cea2f 100644 --- a/2-mandatory/2-financial-times.js +++ b/2-mandatory/2-financial-times.js @@ -5,7 +5,14 @@ Implement the function below, which will return a new array containing only article titles which will fit. */ function potentialHeadlines(allArticleTitles) { + let titles=[]; + for (let i=0; i Date: Fri, 17 Mar 2023 21:41:01 +0000 Subject: [PATCH 3/3] Add a test function to weather report to equal 3 --- 2-mandatory/1-weather-report.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/2-mandatory/1-weather-report.js b/2-mandatory/1-weather-report.js index fce2cb34..4e0ce9e5 100644 --- a/2-mandatory/1-weather-report.js +++ b/2-mandatory/1-weather-report.js @@ -12,16 +12,10 @@ */ function getTemperatureReport(cities) { - let report = []; - for (let i = 0; i < cities.length; i++) { - let temperatureReport = temperatureService(cities[i]); - report.push(`The temperature in ${cities[i]} is ${temperatureReport} degrees`); - } - return report; + return cities.map((city)=>`The temperature in ${city} is ${temperatureService(city)} degrees`); } - // TODO @@ -40,7 +34,10 @@ function temperatureService(city) { return temparatureMap.get(city); } - +test('should return array of same length as argument',()=>{ + let usersCities = ['London', 'Paris', 'Barcelona']; + expect(getTemperatureReport(usersCities).length).toEqual(3); +}) test("should return a temperature report for the user's cities", () => { let usersCities = [ "London",