-
-
Notifications
You must be signed in to change notification settings - Fork 279
MANCHESTER CLASS_NW5 - ANVAR AZIZI - MODULE - javaScript-Core-1-Week3 #125
base: main
Are you sure you want to change the base?
Changes from all commits
852b66f
4264d55
a5ebd8e
c6ecc03
50d97c5
1335e3c
f4c1c94
af2a5d4
7d6c811
1176b91
e759f64
c4c861d
be41cb1
810384c
17b8a1a
094d141
9eaf4ab
efd0bc7
c0d7936
c8748a9
75e9e86
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 |
|---|---|---|
|
|
@@ -13,11 +13,28 @@ const BIRTHDAYS = [ | |
| "July 11th", | ||
| "July 17th", | ||
| "September 28th", | ||
| "November 15th" | ||
| "November 15th", | ||
| ]; | ||
|
|
||
| // let July1 = BIRTHDAYS.filter((x) => x.split(" ")[0] === "July"); | ||
| // console.log(July1.sort()[0]); | ||
|
|
||
| // Good use of split and index here.You could also use "break" | ||
| // to exit the | ||
| // while loop once you have found the first July date. | ||
|
|
||
| function findFirstJulyBDay(birthdays) { | ||
| // TODO | ||
| let july = []; | ||
| let count = 0; | ||
|
|
||
| while (count < birthdays.length) { | ||
| if (birthdays[count].split(" ")[0] === "July") { | ||
| july.push(birthdays[count]); | ||
|
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. Good use of split and index here. You could also use "break" to exit the while loop once you have found the first July date. |
||
| break; | ||
| } | ||
| count++; | ||
| } | ||
| return july.sort()[0]; | ||
| } | ||
|
|
||
| console.log(findFirstJulyBDay(BIRTHDAYS)); // should output "July 11th" | ||
| console.log(findFirstJulyBDay(BIRTHDAYS)); // should output "July 11th" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,11 +4,14 @@ | |
| Change the while loop below into a for loop. | ||
| */ | ||
|
|
||
|
|
||
| // Change the below code to use a for loop instead of a while loop. | ||
| let i = 0; | ||
| while(i < 26) { | ||
| console.log(String.fromCharCode(97 + i)); | ||
| i++; | ||
| } | ||
| // let i = 0; | ||
| // while (i < 26) { | ||
| // console.log(String.fromCharCode(97 + i)); | ||
| // i++; | ||
| // } | ||
| // The output shouldn't change. | ||
|
|
||
| for (let i = 0; i < 26; i++) { | ||
| console.log(String.fromCharCode(65 + i), String.fromCharCode(97 + i)); | ||
| } | ||
|
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. Good work - adding upper case letters wasn't necessary, but it's good to see that you are interested in how fromCharCode works. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,19 +15,15 @@ const WRITERS = [ | |
| "Zadie Smith", | ||
| "Jane Austen", | ||
| "Bell Hooks", | ||
| "Yukiko Motoya" | ||
| ] | ||
|
|
||
| const AGES = [ | ||
| 59, | ||
| 40, | ||
| 41, | ||
| 63, | ||
| 49 | ||
| "Yukiko Motoya", | ||
| ]; | ||
|
|
||
| // TODO - Write for loop code here | ||
| const AGES = [59, 40, 41, 63, 49]; | ||
|
|
||
| // TODO - Write for loop code here | ||
| for (let i = 0; i < WRITERS.length; i++) { | ||
| console.log(`${WRITERS[i]} is ${AGES[i]} years old`); | ||
| } | ||
|
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. Yes, good use of the loop index for both arrays. |
||
| /* | ||
| The output should look something like this: | ||
|
|
||
|
|
@@ -36,4 +32,4 @@ Zadie Smith is 40 years old | |
| Jane Austen is 41 years old | ||
| Bell Hooks is 63 years old | ||
| Yukiko Motoya is 49 years old | ||
| */ | ||
| */ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,9 +8,18 @@ let tubeStations = [ | |
| "Baker Street", | ||
| "Picadilly Circus", | ||
| "Oxford Street", | ||
| "Tottenham Court Road" | ||
| "Tottenham Court Road", | ||
| ]; | ||
|
|
||
|
|
||
| for (let letter of tubeStations) { | ||
| console.log(letter); | ||
| } | ||
| console.log("_____________________"); | ||
| // TODO Use a for-of loop to capitalise and output each letter in the string seperately. | ||
| let str = "codeyourfuture"; | ||
| let capitalise = ""; | ||
| for (let letter of str) { | ||
| capitalise += letter.toUpperCase(); | ||
| console.log(letter.toUpperCase()); | ||
| } | ||
| console.log("_____________________"); | ||
| console.log(capitalise); | ||
|
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. Good you have clearly understood how to use a for loop on an array. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,51 +10,65 @@ | |
| For example, "The temperature in London is 10 degrees" | ||
| - Hint: you can call the temperatureService function from your function | ||
| */ | ||
| // let usersCities = [ | ||
| // "London", | ||
| // "Paris", | ||
| // "Barcelona", | ||
| // "Dubai", | ||
| // "Mumbai", | ||
| // "São Paulo", | ||
| // "Lagos", | ||
| // ]; | ||
|
|
||
| function getTemperatureReport(cities) { | ||
| // TODO | ||
| let city = temperatureService; | ||
| let statementTempCity = cities.map( | ||
| (element) => `The temperature in ${element} is ${city(element)} degrees` | ||
| ); | ||
|
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. Yes, this is very efficient. |
||
| return statementTempCity; | ||
| } | ||
|
|
||
| ///////////////////////////////////////////////////////////// | ||
| // function getTemperatureReport(cities) { | ||
| // let city = temperatureService; | ||
| // return cities.forEach((element) => | ||
| // console.log(`The temperature in ${element} is ${city(element)} degrees`) | ||
| // ); | ||
| // } | ||
| // getTemperatureReport(usersCities); | ||
|
|
||
| /* ======= 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); | ||
| 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" | ||
| ] | ||
| 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" | ||
| "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" | ||
| ] | ||
| let usersCities = ["Barcelona", "Dubai"]; | ||
|
|
||
| expect(getTemperatureReport(usersCities)).toEqual([ | ||
| "The temperature in Barcelona is 17 degrees", | ||
| "The temperature in Dubai is 27 degrees" | ||
| "The temperature in Dubai is 27 degrees", | ||
| ]); | ||
| }); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,11 +8,23 @@ function generateRandomNumber() { | |
| console.log("Generating number..."); | ||
| return Math.round(Math.random() * 100); | ||
| } | ||
| // let randomNum = generateRandomNumber; | ||
|
|
||
| function getRandomNumberGreaterThan50() { | ||
| // TODO - implement using a do-while loop | ||
| } | ||
| let i = 100; | ||
| // let randomNumber = generateRandomNumber; | ||
| do { | ||
| let random = generateRandomNumber(); | ||
| if (random > 50) { | ||
| return random; | ||
| } | ||
|
|
||
| i--; | ||
| } while (i > 50); | ||
|
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. This will exit after 50 loops, so it might not always find a number over 50. But I also understand why you want it to exit so that you don't end up with an endless loop if your logic is wrong. |
||
| } | ||
| // console.log(getRandomNumberGreaterThan50()); | ||
| // getRandomNumberGreaterThan50(); | ||
| /* ======= TESTS - DO NOT MODIFY ===== */ | ||
|
|
||
| test("Returned value should always be greater than 50", () => { | ||
|
|
@@ -21,4 +33,4 @@ test("Returned value should always be greater than 50", () => { | |
| expect(getRandomNumberGreaterThan50()).toBeGreaterThan(50); | ||
| expect(getRandomNumberGreaterThan50()).toBeGreaterThan(50); | ||
| expect(getRandomNumberGreaterThan50()).toBeGreaterThan(50); | ||
| }); | ||
| }); | ||
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.
Good - you have answered all of these correctly.