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
9 changes: 5 additions & 4 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 (answer) a is undefined because nothing has been assigned to it
let a;
console.log(a);


// Example 2
// Example 2 (answer) the variable has not been returned in the function.
function sayHello() {
let message = "Hello";
}
Expand All @@ -28,9 +28,10 @@ function sayHelloToUser(user) {
console.log(`Hello ${user}`);
}

sayHelloToUser();
sayHelloToUser();
// (answer) there is no string when calling this function on line 32.


// Example 4
// Example 4 (answer) there is not a third number in the array the array only has 0, 1, 2 in it.
let arr = [1,2,3];
console.log(arr[3]);
15 changes: 14 additions & 1 deletion 1-exercises/B-while-loop/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,24 @@
Using a while loop, complete the function below so it logs (using console.log) the first n even numbers as a comma-seperated string.
The list of numbers should start with 0. n is being passed in as a parameter.
*/

let limit = 10;
let n = 0;
function evenNumbers(n) {
// TODO

let number = 0
const numList = []
while (number < n && n > 0){
numList.push(number * 2)
number++
}
return numList.join(',')

}

// console.log(evenNumbers(3));
// console.log(evenNumbers(0));
// console.log(evenNumbers(10));
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
13 changes: 12 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,19 @@ const BIRTHDAYS = [
"November 15th"
];



let birthdays = "";
let i = 0;

function findFirstJulyBDay(birthdays) {
// TODO
while (BIRTHDAYS[i]) {
birthdays = BIRTHDAYS[5]
i++;

}
return birthdays;
}

console.log(findFirstJulyBDay(BIRTHDAYS)); // should output "July 11th"
console.log(findFirstJulyBDay(birthdays)); // should output "July 11th"
11 changes: 11 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,17 @@

function evenNumbersSum(n) {
// TODO
if (n === 0) return 0
let x = 0
test = 1
listNum = 0
do {
x += 2
listNum += x
test++
}
while (test < n)
return listNum
}

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

// 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++;
// while(i < 26) {
// console.log(String.fromCharCode(97 + i));
// i++;
// }

for(let i = 65; i <= 90; i++){

console.log(String.fromCharCode(i));
}



// The output shouldn't change.
13 changes: 13 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,19 @@ const AGES = [
49
];

let test = []

// for (let index = 0; index < WRITERS.length; index++) {

// for (let i = 0; i < AGES.length; i++) {
// test.push(WRITERS[index] + AGES[i]);
// console.log(test);
// }
// }

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

/*
Expand Down
13 changes: 12 additions & 1 deletion 1-exercises/F-for-of-loop/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,18 @@ let tubeStations = [
"Oxford Street",
"Tottenham Court Road"
];

let string = "";
for (let index of tubeStations) {
string += index;
console.log(index);
}

// TODO Use a for-of loop to capitalise and output each letter in the string seperately.
let str = "codeyourfuture";

let sentence = "";
for (let x of str) {
sentence += x;
x = x + "";
console.log(x.toUpperCase());
}
68 changes: 33 additions & 35 deletions 2-mandatory/1-weather-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,52 +12,50 @@
*/

function getTemperatureReport(cities) {
// TODO
// TODO
let forCast = [];
for (each of cities) {
let temperature = temperatureService(each);
forCast.push(`The temperature in ${each} is ${temperature} degrees`);
}
return forCast;
}


/* ======= 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([]);
});
5 changes: 5 additions & 0 deletions 2-mandatory/2-retrying-random-numbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ function generateRandomNumber() {

function getRandomNumberGreaterThan50() {
// TODO - implement using a do-while loop
let num = 0;
do {
num = generateRandomNumber();
} while (num <= 50);
return num;
}

/* ======= TESTS - DO NOT MODIFY ===== */
Expand Down
5 changes: 5 additions & 0 deletions 2-mandatory/3-financial-times.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
*/
function potentialHeadlines(allArticleTitles) {
// TODO
return allArticleTitles.filter((test) => {
if (test.length <= 65) return test;
});
}

/*
Expand All @@ -15,6 +18,7 @@ function potentialHeadlines(allArticleTitles) {
*/
function titleWithFewestWords(allArticleTitles) {
// TODO

}

/*
Expand All @@ -24,6 +28,7 @@ function titleWithFewestWords(allArticleTitles) {
*/
function headlinesWithNumbers(allArticleTitles) {
// TODO

}

/*
Expand Down
7 changes: 7 additions & 0 deletions 3-extra/1-factorial.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
*/

function factorial(input) {

let myTest = 1;
for (let index = input; index < 0; index -= 1) {
myTest *= index;
}

return myTest
// TODO
}

Expand Down
8 changes: 8 additions & 0 deletions 3-extra/3-fibonacci.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
*/

function generateFibonacciSequence(n) {
const fibonacci = [0, 1];
for (let i = n - 2; i > 0; i -= 1) {
fibonacci.push(
fibonacci[fibonacci.length - 2] +
fibonacci[fibonacci.length - 1]
);
}
return fibonacci;
// TODO
}

Expand Down