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
7 changes: 6 additions & 1 deletion 1-exercises/A-undefined/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@
// Example 1
let a;
console.log(a);
// we have not assigned a value to 'a' e.g let a = "something"


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

}

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

// we needed a 'return message' inside the function

// Example 3
function sayHelloToUser(user) {
Expand All @@ -30,7 +32,10 @@ function sayHelloToUser(user) {

sayHelloToUser();

// you haven't given the function a parameter e.g "khadija"


// Example 4
let arr = [1,2,3];
console.log(arr[3]);
// the index 3 does not exist in the given array but if we added an extra number e.g 4, it would no longer be undefined.
17 changes: 16 additions & 1 deletion 1-exercises/B-while-loop/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,24 @@
*/

function evenNumbers(n) {
// TODO
// TODO '*'
if(n!== 0){
let i = 0;
let j = 0;
let array = [];

while(i < n){
array.push(j);
i++;
j = (j+2);
}

console.log(array.toString());
}
}



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
7 changes: 7 additions & 0 deletions 1-exercises/C-while-loop-with-array/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ const BIRTHDAYS = [

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

console.log(findFirstJulyBDay(BIRTHDAYS)); // should output "July 11th"
10 changes: 8 additions & 2 deletions 2-mandatory/1-weather-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@
*/

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


Expand All @@ -31,7 +37,7 @@ function temperatureService(city) {

return temparatureMap.get(city);
}

temperatureService("London")
test("should return a temperature report for the user's cities", () => {
let usersCities = [
"London",
Expand Down
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 n;
do {
n = generateRandomNumber();
} while (n < 50)
return n
}

/* ======= TESTS - DO NOT MODIFY ===== */
Expand Down
1 change: 1 addition & 0 deletions 2-mandatory/4-stocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ function getAveragePrices(closingPricesForAllStocks) {
// TODO
}


/*
We also want to see what the change in price is from the first day to the last day for each stock.
Implement the below function, which
Expand Down