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

// There is no value for variable a

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

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

//There is no return in function sayHello()

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

sayHelloToUser();
//function sayHelloToUser needs an input called user


// Example 4
let arr = [1,2,3];
console.log(arr[3]);
// array arr doesn't have index 3
8 changes: 8 additions & 0 deletions 1-exercises/B-while-loop/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@

function evenNumbers(n) {
// TODO
let i = 0
const arr = []
while (i < n && n > 0){
arr.push(i * 2)
console.log(arr[i])
i++
}
return arr.join(',')
}

evenNumbers(3); // should output 0,2,4
Expand Down
2 changes: 2 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,8 @@ const BIRTHDAYS = [

function findFirstJulyBDay(birthdays) {
// TODO
const findFirstJulyBDay = birthdays.filter((bDay) => bDay.startWith("July"))
return findFirstJulyBDay[0]
}

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

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

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

// 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++;
}
Expand Down
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 @@ -27,7 +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] + ' years old ')
}
/*
The output should look something like this:

Expand Down
8 changes: 6 additions & 2 deletions 1-exercises/F-for-of-loop/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ let tubeStations = [
"Oxford Street",
"Tottenham Court Road"
];


for (let i = 0; i < tubeStations.length; i++){
console.log(tubeStations[i]);
}
// TODO Use a for-of loop to capitalise and output each letter in the string seperately.
let str = "codeyourfuture";
for (let i = 0; i < str.length; i++){
console.log(str[i].toUpperCase);
}
6 changes: 6 additions & 0 deletions 2-mandatory/1-weather-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@

function getTemperatureReport(cities) {
// TODO
let TemperatureReport = [i];
for (city of cities){
let cityTemp = temperatureService(city);
TemperatureReport.push('The temperature in ${city} is ${cityTemp} degrees');
}
return TemperatureReport;
}


Expand Down
6 changes: 6 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,12 @@ function generateRandomNumber() {

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

/* ======= TESTS - DO NOT MODIFY ===== */
Expand Down
1 change: 1 addition & 0 deletions 2-mandatory/3-financial-times.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
function potentialHeadlines(allArticleTitles) {
// TODO
return allArticleTitles.filter;
}

/*
Expand Down