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
22 changes: 12 additions & 10 deletions 1-exercises/A-undefined/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,29 @@
*/

// Example 1
let a;
let a = 1;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dear Jud, the question was why is the given expression undefined so, you are expected to explain. for instance, I said that no value was assigned to the variable when declaring.

console.log(a);


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

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

// function sayHello(name) {
// console.log("Hello " + name);
// }
// sayHello("steve");

// Example 3
// https://learn.co/lessons/skills-based-js-intro-to-functions
function sayHelloToUser(user) {
console.log(`Hello ${user}`);
console.log(`Hello, ${user}`);
}

sayHelloToUser();

sayHelloToUser(`Jude`);

// Example 4
let arr = [1,2,3];
console.log(arr[3]);
let arr = [1, 2, 3];
console.log(arr[2]);
23 changes: 22 additions & 1 deletion 1-exercises/B-while-loop/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,31 @@
The list of numbers should start with 0. n is being passed in as a parameter.
*/

// this is a block
function evenNumbers(n) {
// TODO
// while loop is checking for the condition then exicuting the while loop the condition if present
// Initialise, check the condition, the first n even number 0, 2,4,6, run n even number of time,incremete,
num = 0; // starting point o for the count up to n
str = ""; // representing the characters
while (n != num) {
//while I have not reach the number I am counting up to (n) form zero
num++; // num is counting up to n
str += ((num - 1) * 2).toString() + ","; // num holds the number of even numbers with a start point of 0
}
console.log(str.substring(0, str.length - 1)); // remove last charater of a string string
}

//output this
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

/*
1,2,3,4 // 1st, 2nd ,3rd even number so on
2,4,6,8 // actual number


0,1,2,3
0,2,4,6 // Even number scale shifted by one

*/
28 changes: 18 additions & 10 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,27 @@
*/

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

// option 1 while loop
//look for a string in an array and return a string
let i = 0;
function findFirstJulyBDay(birthdays) {
// TODO
while (i < birthdays.length) {
if (birthdays[i].includes(`July`)) {
return birthdays[i];
}
i++;
}
}

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

function evenNumbersSum(n) {
// TODO
i = 0; // not to loop each time
total = 0; //a varialbe to add from the point
do {
i++;
total += i * 2; // adding the even number to total

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dear Jud, I was impressed with how you solved this problem using only two variables. Nice job.

// console.log(i * 2); // test i and or n
} while (i < n); // while i is not up to n
return total - i * 2; // takes away the last even number (shifting the scales back to 0)
}

console.log(evenNumbersSum(3)); // should output 6
console.log(evenNumbersSum(0)); // should output 0
console.log(evenNumbersSum(10)); // should output 90
console.log(evenNumbersSum(10)); // should output 90
18 changes: 12 additions & 6 deletions 1-exercises/E-for-loop/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@
Change the while loop below into a for loop.
*/


// 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++;
}
// let i = 0;
// while (i < 26) {
// console.log(String.fromCharCode(97 + i));
// i++;
// }
// The output shouldn't change.

// asci code i < 26 charcode https://en.wikipedia.org/wiki/List_of_Unicode_characters
// unicode has all letters

for (let i = 0; i < 26; i++) {
console.log(String.fromCharCode(97 + i));
}
26 changes: 12 additions & 14 deletions 1-exercises/E-for-loop/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,20 @@
*/

const WRITERS = [
"Virginia Woolf",
"Zadie Smith",
"Jane Austen",
"Bell Hooks",
"Yukiko Motoya"
]

const AGES = [
59,
40,
41,
63,
49
"Virginia Woolf",
"Zadie Smith",
"Jane Austen",
"Bell Hooks",
"Yukiko Motoya",
];

// TODO - Write for loop code here
const AGES = [59, 40, 41, 63, 49];

// using one loop - as we now the lengthe of eeach loop
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 (let stops of tubeStations) {
console.log(stops);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job! let me drop a little comment I got from my mentor regarding "for of". when you use "for of", you are checking each element of the array so, it is a good practice to write it in a singular form.
for (let stop of tubeStations) {
console.log(stop);
}

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

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

function getTemperatureReport(cities) {
// TODO
temp = []; //initialise an array

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, remember to include a keyword (const temp = [] or let temp = []) when declaring variables, otherwise you could be reassigning a value to a global variable - e.g. there might be another temp variable already declared which you are unaware of.

for (city of cities) {
temp.push(
`The temperature in ` +
city +
` is ` +
String(temperatureService(city)) +
` degrees`
); //the city + its temparature
}
return temp;
}


console.log(getTemperatureReport([`London`, `Paris`, `Barcelona`])); //has to be the exact string
/* ======= 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([]);
});
23 changes: 14 additions & 9 deletions 2-mandatory/2-retrying-random-numbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,25 @@

// This function shouldn't be changed
function generateRandomNumber() {
console.log("Generating number...");
return Math.round(Math.random() * 100);
console.log("Generating number...");
return Math.round(Math.random() * 100); // between 0 - 100
}

function getRandomNumberGreaterThan50() {
// TODO - implement using a do-while loop
// TODO - implement using a do-while loop
n = 0;
do {
n = generateRandomNumber(); // random number between 0 - 100
} while (n <= 50); // Do this until the condition is not met
return n;
}

console.log(getRandomNumberGreaterThan50());
/* ======= TESTS - DO NOT MODIFY ===== */

test("Returned value should always be greater than 50", () => {
expect(getRandomNumberGreaterThan50()).toBeGreaterThan(50);
expect(getRandomNumberGreaterThan50()).toBeGreaterThan(50);
expect(getRandomNumberGreaterThan50()).toBeGreaterThan(50);
expect(getRandomNumberGreaterThan50()).toBeGreaterThan(50);
expect(getRandomNumberGreaterThan50()).toBeGreaterThan(50);
expect(getRandomNumberGreaterThan50()).toBeGreaterThan(50);
expect(getRandomNumberGreaterThan50()).toBeGreaterThan(50);
expect(getRandomNumberGreaterThan50()).toBeGreaterThan(50);
expect(getRandomNumberGreaterThan50()).toBeGreaterThan(50);
expect(getRandomNumberGreaterThan50()).toBeGreaterThan(50);
});
Loading