-
-
Notifications
You must be signed in to change notification settings - Fork 279
Jude Ricketts Week 3 LDB 8 #44
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,9 +7,16 @@ | |
| */ | ||
|
|
||
| function evenNumbersSum(n) { | ||
| // TODO | ||
| i = 0; // not to loop each time | ||
| total = 0; //a varialbe to add from the point | ||
| do { | ||
| i++; | ||
| total += i * 2; // adding the even number to total | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dear Jud, I was impressed with how you solved this problem using only two variables. Nice job. |
||
| // console.log(i * 2); // test i and or n | ||
| } while (i < n); // while i is not up to n | ||
| return total - i * 2; // takes away the last even number (shifting the scales back to 0) | ||
| } | ||
|
|
||
| console.log(evenNumbersSum(3)); // should output 6 | ||
| console.log(evenNumbersSum(0)); // should output 0 | ||
| console.log(evenNumbersSum(10)); // should output 90 | ||
| console.log(evenNumbersSum(10)); // should output 90 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,13 +4,19 @@ | |
|
|
||
| // TODO Use a for-of loop to output each of the tube stations below. | ||
| let tubeStations = [ | ||
| "Aldgate", | ||
| "Baker Street", | ||
| "Picadilly Circus", | ||
| "Oxford Street", | ||
| "Tottenham Court Road" | ||
| "Aldgate", | ||
| "Baker Street", | ||
| "Picadilly Circus", | ||
| "Oxford Street", | ||
| "Tottenham Court Road", | ||
| ]; | ||
|
|
||
|
|
||
| for (let stops of tubeStations) { | ||
| console.log(stops); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice job! let me drop a little comment I got from my mentor regarding "for of". when you use "for of", you are checking each element of the array so, it is a good practice to write it in a singular form. |
||
| } | ||
| // TODO Use a for-of loop to capitalise and output each letter in the string seperately. | ||
| let str = "codeyourfuture"; | ||
|
|
||
| for (let letters of str) { | ||
| console.log(letters.toUpperCase()); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,52 +12,55 @@ | |
| */ | ||
|
|
||
| function getTemperatureReport(cities) { | ||
| // TODO | ||
| temp = []; //initialise an array | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In general, remember to include a keyword ( |
||
| for (city of cities) { | ||
| temp.push( | ||
| `The temperature in ` + | ||
| city + | ||
| ` is ` + | ||
| String(temperatureService(city)) + | ||
| ` degrees` | ||
| ); //the city + its temparature | ||
| } | ||
| return temp; | ||
| } | ||
|
|
||
|
|
||
| console.log(getTemperatureReport([`London`, `Paris`, `Barcelona`])); //has to be the exact string | ||
| /* ======= TESTS - DO NOT MODIFY ===== */ | ||
|
|
||
| function temperatureService(city) { | ||
| let temparatureMap = new Map(); | ||
|
|
||
| temparatureMap.set('London', 10); | ||
| temparatureMap.set('Paris', 12); | ||
| temparatureMap.set('Barcelona', 17); | ||
| temparatureMap.set('Dubai', 27); | ||
| temparatureMap.set('Mumbai', 29); | ||
| temparatureMap.set('São Paulo', 23); | ||
| temparatureMap.set('Lagos', 33); | ||
| return temparatureMap.get(city); | ||
| let temparatureMap = new Map(); | ||
|
|
||
| temparatureMap.set("London", 10); | ||
| temparatureMap.set("Paris", 12); | ||
| temparatureMap.set("Barcelona", 17); | ||
| temparatureMap.set("Dubai", 27); | ||
| temparatureMap.set("Mumbai", 29); | ||
| temparatureMap.set("São Paulo", 23); | ||
| temparatureMap.set("Lagos", 33); | ||
|
|
||
| return temparatureMap.get(city); | ||
| } | ||
|
|
||
| test("should return a temperature report for the user's cities", () => { | ||
| let usersCities = [ | ||
| "London", | ||
| "Paris", | ||
| "São Paulo" | ||
| ] | ||
|
|
||
| expect(getTemperatureReport(usersCities)).toEqual([ | ||
| "The temperature in London is 10 degrees", | ||
| "The temperature in Paris is 12 degrees", | ||
| "The temperature in São Paulo is 23 degrees" | ||
| ]); | ||
| let usersCities = ["London", "Paris", "São Paulo"]; | ||
|
|
||
| expect(getTemperatureReport(usersCities)).toEqual([ | ||
| "The temperature in London is 10 degrees", | ||
| "The temperature in Paris is 12 degrees", | ||
| "The temperature in São Paulo is 23 degrees", | ||
| ]); | ||
| }); | ||
|
|
||
| test("should return a temperature report for the user's cities (alternate input)", () => { | ||
| let usersCities = [ | ||
| "Barcelona", | ||
| "Dubai" | ||
| ] | ||
|
|
||
| expect(getTemperatureReport(usersCities)).toEqual([ | ||
| "The temperature in Barcelona is 17 degrees", | ||
| "The temperature in Dubai is 27 degrees" | ||
| ]); | ||
| let usersCities = ["Barcelona", "Dubai"]; | ||
|
|
||
| expect(getTemperatureReport(usersCities)).toEqual([ | ||
| "The temperature in Barcelona is 17 degrees", | ||
| "The temperature in Dubai is 27 degrees", | ||
| ]); | ||
| }); | ||
|
|
||
| test("should return an empty array if the user hasn't selected any cities", () => { | ||
| expect(getTemperatureReport([])).toEqual([]); | ||
| }); | ||
| expect(getTemperatureReport([])).toEqual([]); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dear Jud, the question was why is the given expression undefined so, you are expected to explain. for instance, I said that no value was assigned to the variable when declaring.