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

// a has no value assigned

// Example 2
function sayHello() {
let message = "Hello";
}
// the function sayHello is not returned

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

// the function is not returning anything

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

// the user parameter does not pass anything
sayHelloToUser();


// Example 4
let arr = [1,2,3];
console.log(arr[3]);
// there is no index 3 in the array
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 @@ -6,6 +6,14 @@
*/

function evenNumbers(n) {
const arr = []
let i = 0

while (i < n) {
arr.push(i * 2);
i++;
}
console.log(arr.join(', '));
// TODO
}

Expand Down
9 changes: 9 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,15 @@ const BIRTHDAYS = [
];

function findFirstJulyBDay(birthdays) {
let i = 0;

while (i < birthdays.length - 1) {
let birthdayCheck = birthdays[i];
if (birthdayCheck.startsWith("July")) {
return birthdayCheck;
}
i++;
}
// TODO
}

Expand Down
8 changes: 8 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,14 @@

function evenNumbersSum(n) {
// TODO
let sumNum = 0;
let i = 0;

do {
sumNum = sumNum + i * 2;
i++;
} while (i < n);
return sumNum;
}

console.log(evenNumbersSum(3)); // should output 6
Expand Down
13 changes: 8 additions & 5 deletions 1-exercises/E-for-loop/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@


// 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.
for (let i = 0; i < 26 ; i++) {
console.log(String.fromCharCode(97 + i));
}
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]} years old`)
}

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

for (const station of tubeStations) {
console.log(station.toUpperCase());
}

// TODO Use a for-of loop to capitalise and output each letter in the string seperately.
let str = "codeyourfuture";
for (const letter of str) {
console.log(letter.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 arrTemp = [];

for (let city of cities) {
arrTemp.push(`The temperature in ${city} is ${temperatureService(city)} degrees`);
}
return arrTemp;
}


Expand Down
7 changes: 7 additions & 0 deletions 2-mandatory/2-retrying-random-numbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,15 @@ function generateRandomNumber() {

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

return number;
}


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

test("Returned value should always be greater than 50", () => {
Expand Down
21 changes: 21 additions & 0 deletions 2-mandatory/3-financial-times.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
*/
function potentialHeadlines(allArticleTitles) {
// TODO

let titles = [];

for (const title in allArticleTitles) {
if (titles.length <= 65) {
titles.push(title);
}
}
return titles;
}

/*
Expand All @@ -15,6 +24,17 @@ function potentialHeadlines(allArticleTitles) {
*/
function titleWithFewestWords(allArticleTitles) {
// TODO
let fewWords = allArticleTitles[0];
let words = allArticleTitles[0].split(" ").length;

for (let i = 0; i < allArticleTitles.length; i++) {
let theWordArrapy = allArticleTitles[i].split(" ").length;
if (theWordArray < words) {
fewWords = allArticleTitles[i];
}
words = theWordArrapy;
}
return fewWords;
}

/*
Expand All @@ -24,6 +44,7 @@ function titleWithFewestWords(allArticleTitles) {
*/
function headlinesWithNumbers(allArticleTitles) {
// TODO

}

/*
Expand Down
27 changes: 0 additions & 27 deletions 3-extra/1-factorial.js

This file was deleted.

82 changes: 0 additions & 82 deletions 3-extra/2-array-of-objects.js

This file was deleted.

37 changes: 0 additions & 37 deletions 3-extra/3-fibonacci.js

This file was deleted.