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
6 changes: 6 additions & 0 deletions 1-exercises/A-undefined/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
let a;
console.log(a);

variable a is not assigned to a value

// Example 2
function sayHello() {
Expand All @@ -22,6 +23,7 @@ function sayHello() {
let hello = sayHello();
console.log(hello);

sayHello is a function that has not been defined nor does it have a return value or a parameter

// Example 3
function sayHelloToUser(user) {
Expand All @@ -31,6 +33,10 @@ function sayHelloToUser(user) {
sayHelloToUser();


sayHelloToUser does not have a parameter therefore user has no value

// Example 4
let arr = [1,2,3];
console.log(arr[3]);

console.log is calling index 3 however there are only 2 as the index starts at 0
10 changes: 9 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,15 @@
*/

function evenNumbers(n) {
// TODO
let myArray = [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20];
let i = 0;
let str = "";
while (i < n) {
str += myArray[i] + ",";
i++;
}
console.log(str);
// TODO
}

evenNumbers(3); // should output 0,2,4
Expand Down
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 @@ -17,6 +17,13 @@ const BIRTHDAYS = [
];

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

Expand Down
12 changes: 12 additions & 0 deletions 1-exercises/D-do-while/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,19 @@
*/

function evenNumbersSum(n) {
evenNumArray = [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22];
let i = 0;
let sum = 0;
do {
sum += evenNumArray[i];
i++;

}
while (i < n) {
return sum;
}
// TODO

}

console.log(evenNumbersSum(3)); // should output 6
Expand Down
4 changes: 4 additions & 0 deletions 1-exercises/E-for-loop/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ while(i < 26) {
console.log(String.fromCharCode(97 + i));
i++;
}

for (let i = 0; i < 26; i++) {
console.log(String.fromCharCode(97 + i));
}
// The output shouldn't change.
3 changes: 3 additions & 0 deletions 1-exercises/E-for-loop/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ const AGES = [
];

// TODO - Write for loop code here
for (let i = 0; i < WRITERS.length; i++) {
console.log(`${WRITERS[i]} is ${AGES[i]}`);
}

/*
The output should look something like this:
Expand Down
10 changes: 10 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,16 @@ let tubeStations = [
"Tottenham Court Road"
];

for (tubeStation of tubeStations) {
console.log(tubeStation);
}


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

for (let i of str) {
word = i.trim();
console.log(word.toUpperCase());
}
8 changes: 8 additions & 0 deletions 2-mandatory/2-retrying-random-numbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ function generateRandomNumber() {
}

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

Expand Down