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
10 changes: 5 additions & 5 deletions 1-exercises/A-undefined/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
For each example, can you explain why we are seeing undefined?
*/

// Example 1
// Example 1 - a wasn't declared
let a;
console.log(a);


// Example 2
// Example 2 - I didn't return any value
function sayHello() {
let message = "Hello";
}
Expand All @@ -23,14 +23,14 @@ let hello = sayHello();
console.log(hello);


// Example 3
// Example 3 - I didn't pass any parameter when I called the function sayHelloToUser
function sayHelloToUser(user) {
console.log(`Hello ${user}`);
}

sayHelloToUser();


// Example 4
// Example 4 - the last number of my array is 3, but the position is 2, so when I call position 3 is undefined
let arr = [1,2,3];
console.log(arr[3]);
console.log(arr[3]);
21 changes: 17 additions & 4 deletions 1-exercises/B-while-loop/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,22 @@
*/

function evenNumbers(n) {
// TODO
let evenNumbersUntiln=0;
let i=1;

while(i < n){
evenNumbersUntiln = evenNumbersUntiln + "," + 2 * i;
i++;
}

if(n !== 0){
return evenNumbersUntiln;
} else {
return "nothing";
}

}

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
console.log(evenNumbers(3)); // should output 0,2,4
console.log(evenNumbers(0)); // should output nothing
console.log(evenNumbers(10)); // should output 0,2,4,6,8,10,12,14,16,18
12 changes: 11 additions & 1 deletion 1-exercises/C-while-loop-with-array/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,18 @@ const BIRTHDAYS = [
"November 15th"
];

let firstBirthday;

function findFirstJulyBDay(birthdays) {
// TODO
for(let i=0;i<BIRTHDAYS.length;i++){
firstBirthday = BIRTHDAYS[i].split(" ");
if(firstBirthday[0]=="July"){
return BIRTHDAYS[i];
}
}
}

console.log(findFirstJulyBDay(BIRTHDAYS)); // should output "July 11th"


console.log(findFirstJulyBDay(BIRTHDAYS)); // should output "July 11th"
14 changes: 12 additions & 2 deletions 1-exercises/D-do-while/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,19 @@

Using a do-while loop, write a function which returns the sum of the first n even numbers (starting from 0)
*/

function evenNumbersSum(n) {
// TODO

let evenNumberSumUntiln=0;
let sumNum = 0;
let counter =0;

do {
evenNumberSumUntiln += sumNum;
sumNum += 2;
counter++;
} while (counter < n);

return evenNumberSumUntiln;
}

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


// Change the below code to use a for loop instead of a while loop.
let i = 0;
while(i < 26) {
for(let i=0;i < 26;i++) {
console.log(String.fromCharCode(97 + i));
i++;
}
// The output shouldn't change.
4 changes: 4 additions & 0 deletions 1-exercises/E-for-loop/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ const AGES = [
49
];

for(let i=0;i<WRITERS.length;i++){
console.log(`${WRITERS[i]} is ${AGES[i]} years old`);
}

// TODO - Write for loop code here

/*
Expand Down
8 changes: 8 additions & 0 deletions 1-exercises/F-for-of-loop/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ let tubeStations = [
"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 letter of str){
let capitaliseLetter = letter.toUpperCase();
console.log(capitaliseLetter);
}
85 changes: 42 additions & 43 deletions 2-mandatory/1-weather-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,52 +12,51 @@
*/

function getTemperatureReport(cities) {
// TODO
}


/* ======= 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 cityNameAndDegree = [];

for (let city of cities) {
cityNameAndDegree.push(
`The temperature in ${city} is ${temperatureService(city)} degrees`
);
}
return cityNameAndDegree;
}

/* ======= 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);
}

test("should return a temperature report for the user's cities", () => {
let usersCities = [
"London",
"Paris",
"São Paulo"
]

}

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"
"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"
]

});

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"
"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", () => {
});
test("should return an empty array if the user hasn't selected any cities", () => {
expect(getTemperatureReport([])).toEqual([]);
});
});
10 changes: 8 additions & 2 deletions 2-mandatory/2-retrying-random-numbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ function generateRandomNumber() {
}

function getRandomNumberGreaterThan50() {
// TODO - implement using a do-while loop
let randonNumber;

do{
randonNumber = generateRandomNumber();
}while(randonNumber <= 50);

return randonNumber;
}

/* ======= TESTS - DO NOT MODIFY ===== */
Expand All @@ -21,4 +27,4 @@ test("Returned value should always be greater than 50", () => {
expect(getRandomNumberGreaterThan50()).toBeGreaterThan(50);
expect(getRandomNumberGreaterThan50()).toBeGreaterThan(50);
expect(getRandomNumberGreaterThan50()).toBeGreaterThan(50);
});
});
Loading