Skip to content
This repository was archived by the owner on Jan 14, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions 1-exercises/A-undefined/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ sayHelloToUser();


// Example 4
let arr = [1,2,3];
console.log(arr[3]);
let arr = [1, 2, 3];
console.log(arr[3]);
11 changes: 8 additions & 3 deletions 1-exercises/B-while-loop/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@

function evenNumbers(n) {
// TODO
let i = 0;
while (i < n) {
console.log(i * 2);
i++
}
}

evenNumbers(3); // should output 0,2,4
evenNumbers(0); // should output nothing
evenNumbers(10); // should output 0,2,4,6,8,10,12,14,16,18
// evenNumbers(3); // should output 0,2,4
// evenNumbers(0); // should output nothing
evenNumbers(10); // should output 0,2,4,6,8,10,12,14,16,18
11 changes: 9 additions & 2 deletions 1-exercises/C-while-loop-with-array/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@ const BIRTHDAYS = [
"July 11th",
"July 17th",
"September 28th",
"November 15th"
"November 15th",
];

function findFirstJulyBDay(birthdays) {
// TODO
i = 0;
while (i < birthdays.lenght) {
if (birthdays[i].includes("July")) {
return birthdays[i];
}
i++
}
}

console.log(findFirstJulyBDay(BIRTHDAYS)); // should output "July 11th"
console.log(findFirstJulyBDay(BIRTHDAYS)); // should output "July 11th"
7 changes: 7 additions & 0 deletions 1-exercises/D-do-while/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@

function evenNumbersSum(n) {
// TODO
let result = "";
let i = 0;
do {
i += 1;
result += '${n * (n - 1)} ';
} while (i < 1);
return result;
}

console.log(evenNumbersSum(3)); // should output 6
Expand Down
7 changes: 5 additions & 2 deletions 1-exercises/E-for-loop/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@

// Change the below code to use a for loop instead of a while loop.
let i = 0;
while(i < 26) {
while (i < 26) {
console.log(String.fromCharCode(97 + i));
i++;
for (i = 0; i < 26; i++) {
console.log(String.fromCharCode(97 + i));
}
}
// The output shouldn't change.
// The output shouldn't change.
21 changes: 11 additions & 10 deletions 1-exercises/E-for-loop/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@ const WRITERS = [
"Zadie Smith",
"Jane Austen",
"Bell Hooks",
"Yukiko Motoya"
]

const AGES = [
59,
40,
41,
63,
49
"Yukiko Motoya",
];

const AGES = [59, 40, 41, 63, 49];

// TODO - Write for loop code here
for (i = 0; i < WRITERS.length; i++) {
console.log(`${WRITERS[i]} is ${AGES[i]} years old`);
}

/*

// TODO - Write for loop code here

/*
Expand All @@ -36,4 +37,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
*/
*/
9 changes: 7 additions & 2 deletions 1-exercises/F-for-of-loop/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,14 @@ let tubeStations = [
"Baker Street",
"Picadilly Circus",
"Oxford Street",
"Tottenham Court Road"
"Tottenham Court Road",
];

for (let stations of tubeStations) {
console.log(stations);
}

// TODO Use a for-of loop to capitalise and output each letter in the string seperately.
let str = "codeyourfuture";
for (let charCaps of str) {
console.log(charCaps.toUpperCase());
}
42 changes: 27 additions & 15 deletions 2-mandatory/1-weather-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,43 @@

function getTemperatureReport(cities) {
// TODO
let cityTemp = [];
for (let i = 0; i < cities.length; i++) {
cityTemp.push(
`The temperature in ${cities[i]} is ${temperatureService(
cities[i]
)} degrees`
);
}
return cityTemp;
}


/* ======= 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",
]);


expect(getTemperatureReport(usersCities)).toEqual([
"The temperature in London is 10 degrees",
Expand Down