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
12 changes: 10 additions & 2 deletions 1-exercises/A-undefined/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@

// Example 1
let a;
// the variable a has not given a value()
// a = "Thank you for checking my work"
console.log(a);


// Example 2
function sayHello() {
let message = "Hello";
let message = "Hello";
/*the variable message is not called on the second line
example */
// return message;
}

let hello = sayHello();
Expand All @@ -27,10 +32,13 @@ console.log(hello);
function sayHelloToUser(user) {
console.log(`Hello ${user}`);
}

// user doesn't have values in it
sayHelloToUser();
// sayHelloToUser("my friend");


// Example 4
let arr = [1,2,3];
console.log(arr[3]);
// console.log(arr[2])
//On the console have selected a number in the array which doesn't exit. javascript counts starting from 0
12 changes: 12 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,18 @@

function evenNumbers(n) {
// TODO
i = 0;
y = n;
let x = "";
if (n > 0) {
while (i < y) {
x += i + ",";
i += 2;
}
console.log(x);
} else {
// console.log("nothing");
}
}

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

function findFirstJulyBDay(birthdays) {
// TODO
// TODO
let capture = "";
for (let i = 0; i < birthdays.length; i += 6) {
const index = birthdays[i];
index;
capture += index;
console.log(index);
}
}

console.log(findFirstJulyBDay(BIRTHDAYS)); // should output "July 11th"
// console.log(findFirstJulyBDay(BIRTHDAYS)); // should output "July 11th"
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 i = 0;
let message = "Total";
let capture = "";
do {
let sum = message + capture[i];
console.log(sum);
i * 2;
} while (i < n);
}

console.log(evenNumbersSum(3)); // should output 6
Expand Down
11 changes: 7 additions & 4 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++;
// }
for (let i = 0; i < 29; i++) {
console.log(String.fromCharCode(94 + i));
}
// The output shouldn't change.
12 changes: 12 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,18 @@ const AGES = [
];

// TODO - Write for loop code here
let capture = "";
for (let i = 0; i < WRITERS.length; i++) {
const name = WRITERS[i]
const age = AGES[i]
console.log(name, age, "years old")
}
// for (var i in WRITERS) {
// for (var a in AGES) {
// capture += WRITERS[i] + AGES[a];
// console.log(capture);
// }
// }

/*
The output should look something like this:
Expand Down
16 changes: 15 additions & 1 deletion 1-exercises/F-for-of-loop/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,19 @@ let tubeStations = [
];


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

// TODO 1
for (let i = 0; i < tubeStations.length; i++) {
const index = tubeStations[i];
console.log(index);
}

// TODO 2
let capture = ""
for (let i = 0; i < str.length; i++) {
capture += str[i];
}

console.log(capture.toUpperCase());
8 changes: 7 additions & 1 deletion 2-mandatory/1-weather-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@
*/

function getTemperatureReport(cities) {
// TODO
// TODO
let temperature = [];
for (city of cities) {
let temp = temperatureService(city);
temperature.push("The temperature in", city, " is ", temp, " degrees");
}
return temperature;
}


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

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

/* ======= TESTS - DO NOT MODIFY ===== */
Expand Down
25 changes: 21 additions & 4 deletions 2-mandatory/3-financial-times.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,49 @@
*/
function potentialHeadlines(allArticleTitles) {
// TODO
const article = allArticleTitles.filter((article) => article.length <= 65);
return article;
}

/*
The editor of the FT likes short headlines with only a few words!
Implement the function below, which returns the title with the fewest words.
(you can assume words will always be seperated by a space)
(you can assume words will always be separated by a space)
*/
function titleWithFewestWords(allArticleTitles) {
// TODO
// TODO
const outputOfArticle = allArticleTitles[0];
for (let i = 0; i < allArticleTitles.length; i++) {
if (
allArticleTitles[i].split(" ").length < outputOfArticle.split(" ").length
)
outputOfArticle = allArticleTitles[i];
}
return outputOfArticle;
}

/*
The editor of the FT has realised that headlines which have numbers in them get more clicks!
The editor of the FT has realized that headlines which have numbers in them get more clicks!
Implement the function below to return a new array containing all the headlines which contain a number.
(Hint: remember that you can also loop through the characters of a string if you need to)
*/
function headlinesWithNumbers(allArticleTitles) {
// TODO
}
const title = allArticleTitles.filter((article) => article.match(/(\d+)/));
return title

/*
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
const total = 0;
for (let title of allArticleTitles) {
total += title.length;
}
let average = total / allArticleTitles.length;
return Math.round(average);
}


Expand Down
12 changes: 10 additions & 2 deletions 2-mandatory/4-stocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,14 @@ const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [
Functions can help with this!
*/
function getAveragePrices(closingPricesForAllStocks) {
// TODO
// TODO
return closingPricesForAllStocks.map((priceArr) => {
return Number(
(priceArr.reduce((tot, num) => tot + num) / priceArr.length).toFixed(2)
);
});
}

/*
We also want to see what the change in price is from the first day to the last day for each stock.
Implement the below function, which
Expand All @@ -49,6 +54,9 @@ function getAveragePrices(closingPricesForAllStocks) {
*/
function getPriceChanges(closingPricesForAllStocks) {
// TODO
return closingPricesForAllStocks.map((priceArr) => {
return Number((priceArr[priceArr.length - 1] - priceArr[0]).toFixed(2));
});
}

/*
Expand Down