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
11 changes: 8 additions & 3 deletions 1-exercises/A-undefined/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,30 @@
// Example 1
let a;
console.log(a);

// a has not a value that's why undefined.

// Example 2
function sayHello() {
let message = "Hello";
}

// function has not a return part.

let hello = sayHello();
console.log(hello);

// There is nothing in the paranthesis of sayHello.

// Example 3
function sayHelloToUser(user) {
console.log(`Hello ${user}`);
}

sayHelloToUser();

// function call has no argument

// Example 4
let arr = [1,2,3];
console.log(arr[3]);
// There is not any element at the index(3). Array index ends at 2.

//No questions
11 changes: 10 additions & 1 deletion 1-exercises/B-while-loop/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@
*/

function evenNumbers(n) {
// TODO
const even = [0, 2, 4, 6, 8, 10, 12, 14, 16, 18];

let string = "";
let count = 0;
while (count < n) {
string += `${even[count]},`;
count++;
}

console.log(string);
}

evenNumbers(3); // should output 0,2,4
Expand Down
28 changes: 17 additions & 11 deletions 1-exercises/C-while-loop-with-array/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,25 @@
*/

const BIRTHDAYS = [
"January 7th",
"February 12th",
"April 3rd",
"April 5th",
"May 3rd",
"July 11th",
"July 17th",
"September 28th",
"November 15th"
"January 7th",
"February 12th",
"April 3rd",
"April 5th",
"May 3rd",
"July 11th",
"July 17th",
"September 28th",
"November 15th",
];

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

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


//Ask about upper-lowercase.
12 changes: 11 additions & 1 deletion 1-exercises/D-do-while/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@
*/

function evenNumbersSum(n) {
// TODO
const even = [0, 2, 4, 6, 8, 10, 12, 14, 16, 18];

let string = "";
let counter= 0;

do {
string += `${even[counter]},`;
counter++;
} while (counter < n);

return string;
}

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


// 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.
5 changes: 3 additions & 2 deletions 1-exercises/E-for-loop/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ const AGES = [
49
];

// TODO - Write for loop code here

for (let i = 0; i < WRITERS.length; i++) {
console.log(WRITERS[i] + " is "+ AGES[i] + " years old");
}
/*
The output should look something like this:

Expand Down
18 changes: 12 additions & 6 deletions 1-exercises/F-for-of-loop/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (const element of tubeStations) {
console.log(element);
}
// TODO Use a for-of loop to capitalise and output each letter in the string seperately.
let str = "codeyourfuture";

for (let char of str) {
console.log(char.toUpperCase());
}
67 changes: 32 additions & 35 deletions 2-mandatory/1-weather-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,52 +12,49 @@
*/

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


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

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

return call;
}

/* ======= TESTS - DO NOT MODIFY ===== */
Expand Down
28 changes: 25 additions & 3 deletions 2-mandatory/4-stocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,16 @@ const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [
Functions can help with this!
*/
function getAveragePrices(closingPricesForAllStocks) {
// TODO
for (let i of closingPricesForAllStocks) {
let total = 0;
for (let j in i) {
total += i[j];
}
let a = total / i.length;
let b = Number(a.toFixed(2));
arrayOfAverage.push(b);
}
return arrayOfAverage;
}

/*
Expand All @@ -48,7 +57,12 @@ function getAveragePrices(closingPricesForAllStocks) {
The price change value should be rounded to 2 decimal places, and should be a number (not a string)
*/
function getPriceChanges(closingPricesForAllStocks) {
// TODO
let priceChanges = [];
for (let array of closingPricesForAllStocks) {
let output = array[array.length - 1] - array[0];
priceChanges.push(Number(output.toFixed(2)));
}
return priceChanges;
}

/*
Expand All @@ -64,7 +78,15 @@ function getPriceChanges(closingPricesForAllStocks) {
The price should be shown with exactly 2 decimal places.
*/
function highestPriceDescriptions(closingPricesForAllStocks, stocks) {
// TODO
let returnMyArray = [];
for (let index in closingPricesForAllStocks) {
let largestNumber = Math.max(...closingPricesForAllStocks[index]);
let outputWithQuote = `The highest price of ${stocks[
index
].toUpperCase()} in the last 5 days was ${largestNumber.toFixed(2)}`;
returnMyArray.push(outputWithQuote);
}
return returnMyArray;
}


Expand Down
5 changes: 4 additions & 1 deletion 3-extra/1-factorial.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
*/

function factorial(input) {
// TODO
for (var i = input - 1; i >= 1; i--) {
input *= i;
}
return input;
}

/* ======= TESTS - DO NOT MODIFY ===== */
Expand Down