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: 5 additions & 2 deletions 1-exercises/A-undefined/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// Example 1
let a;
console.log(a);
// variable a doesn't have assigned a value;


// Example 2
Expand All @@ -21,16 +22,18 @@ function sayHello() {

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

// function sayHello doesn't have return;

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

sayHelloToUser();
// function sayHelloTo User doesn't have a argument for user;


// Example 4
let arr = [1,2,3];
let arr = [1, 2, 3];
console.log(arr[3]);
//array has just 3 elements and console.log is asking 4-th element;
8 changes: 7 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,13 @@
*/

function evenNumbers(n) {
// TODO
let arr = [];
let i = 0;
while (arr.length < n) {
arr.push(i);
i++;
}
return arr.join(',');
}

evenNumbers(3); // should output 0,2,4
Expand Down
8 changes: 7 additions & 1 deletion 1-exercises/C-while-loop-with-array/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ const BIRTHDAYS = [
];

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

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

function evenNumbersSum(n) {
// TODO
let i = 0;
let sum = 0;
do { sum += i * 2; i++; } while (i < n);
return sum;
}

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) {

while (let i = 0; i < 26; i++) {
console.log(String.fromCharCode(97 + i));
i++;

}
// The output shouldn't change.
4 changes: 3 additions & 1 deletion 1-exercises/E-for-loop/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ const AGES = [
49
];

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

/*
The output should look something like this:
Expand Down
11 changes: 11 additions & 0 deletions 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 newStr = '';
for (let i of tubeStations) {
newStr += i;
console.log(i);
}


// TODO Use a for-of loop to capitalise and output each letter in the string seperately.
let str = "codeyourfuture";
let otherStr = '';
for (let i of str) {
otherStr += i;
console.log(i.toUpperCase());
}

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 number;
do {
number = generateRandomNumber();
} while (number < 51);
return number

}

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