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
15 changes: 8 additions & 7 deletions 1-exercises/A-undefined/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,29 @@
For each example, can you explain why we are seeing undefined?
*/

// Example 1
let a;
// Example 1 // => the variable is not assinged to any value.
let a;
console.log(a);


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

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


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

sayHelloToUser();
sayHelloToUser(); // index 3 is has no value


// Example 4
let arr = [1,2,3];
console.log(arr[3]);
console.log(arr[3]);
8 changes: 7 additions & 1 deletion 1-exercises/B-while-loop/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@



/*
while loops can be useful when you want to execute some code as long as some condition is true.

Expand All @@ -6,7 +9,10 @@
*/

function evenNumbers(n) {
// TODO
let even = 0;
while(n%2 == 0) {
console.log(even * 2);
}
}

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

function findFirstJulyBDay(birthdays) {
// TODO
let jul = 0;
while(jul < BIRTHDAYS.length) {

if(BIRTHDAYS[jul].includes('July')) {
return BIRTHDAYS[jul];

}
jul++
}
}

console.log(findFirstJulyBDay(BIRTHDAYS)); // should output "July 11th"
4 changes: 2 additions & 2 deletions 1-exercises/E-for-loop/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@


// Change the below code to use a for loop instead of a while loop.
let i = 0;
while(i < 26) {
// let i = 0;
for (i = 0;i < 26;i++) {
console.log(String.fromCharCode(97 + i));
i++;
}
Expand Down
8 changes: 7 additions & 1 deletion 1-exercises/E-for-loop/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,14 @@ const AGES = [
49
];

// TODO - Write for loop code here


for (i=0; i< AGES.length; i++) {

console.log(`${WRITERS[i]} is ${AGES[i]} years old `);


}
/*
The output should look something like this:

Expand Down
11 changes: 10 additions & 1 deletion 1-exercises/F-for-of-loop/exercise.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
A for-of loop is a easy and way of looping through the elements of an array, string or any other "iterable object" (think sequence of elements).
A for-of loop is a easy and way of looping through the elements of an array, string or any other "iterable object"
(think sequence of elements).
*/

// TODO Use a for-of loop to output each of the tube stations below.
Expand All @@ -11,6 +12,14 @@ let tubeStations = [
"Tottenham Court Road"
];

for (let i of tubeStations) {
console.log(i);
}


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

for (let j of str) {
console.log(j.toUpperCase());
}
16 changes: 15 additions & 1 deletion 2-mandatory/1-weather-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,24 @@
*/

function getTemperatureReport(cities) {
// TODO
const temp = [];
for(let city in cities ) {
temp.push(`the temperature in ${city} is ${temperatureService(city)} degrees`);
}
return temp;
}












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

function temperatureService(city) {
Expand Down
12 changes: 11 additions & 1 deletion 2-mandatory/2-retrying-random-numbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,19 @@ function generateRandomNumber() {
}

function getRandomNumberGreaterThan50() {
// TODO - implement using a do-while loop

let i = 0;
do {
let i = generateRandomNumber();
} while(i > 50);


return i;
}




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

test("Returned value should always be greater than 50", () => {
Expand Down
25 changes: 24 additions & 1 deletion 2-mandatory/3-financial-times.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
*/
function potentialHeadlines(allArticleTitles) {
// TODO
return allArticleTitles.filter(x => x.length <= 65);



}

/*
Expand All @@ -15,6 +19,10 @@ function potentialHeadlines(allArticleTitles) {
*/
function titleWithFewestWords(allArticleTitles) {
// TODO


let shortest = allArticleTitles.reduce((shortest, current) => current.length <= shortest.length ? current : shortest);
return shortest;
}

/*
Expand All @@ -24,14 +32,29 @@ function titleWithFewestWords(allArticleTitles) {
*/
function headlinesWithNumbers(allArticleTitles) {
// TODO
}
let titleWitNum = allArticleTitles.filter((title) => {
typeof title == 'number'

});
return titleWitNum


}


/*
The Financial Times wants to understand what the average number of characters in an article title is.
Implement the function below to return this number - rounded to the nearest integer.
*/
function averageNumberOfCharacters(allArticleTitles) {
// TODO
let all = 0;

for (let title of allArticleTitles) {
all += title.length;
}

return Math.round(all / allArticleTitles.length);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Great piece of code. Looks elegant and functional.



Expand Down
5 changes: 5 additions & 0 deletions 3-extra/1-factorial.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@

function factorial(input) {
// TODO
let result = 1;
for (let i = 1; i<= input; i++) {
result*= i;
}
return result;
}

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