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: 6 additions & 0 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);
// the reason why we are seeing undefined for a has no value assigned


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

let hello = sayHello();
console.log(hello);
// the function is undefined because it has not returned 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 the index goes up to 2

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
const arr = []
let i = 0

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

evenNumbers(3); // should output 0,2,4
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")) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How about using 'includes' method?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

.starts with July! Always learning! I have used the .includes method but it is nice to see other ways of doing it

return birthdayCheck;
}
i++;
}
// TODO
}

Expand Down
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) {
Comment thread
12shussein marked this conversation as resolved.
// 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
4 changes: 1 addition & 3 deletions 1-exercises/E-for-loop/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,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++;
}
// The output shouldn't change.
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++){

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I see that You understand the for loop logic. Nicely done!

console.log(WRITERS[i] + ' is ' + AGES[i] + ' years old ')
}

/*
The output should look something like this:
Expand Down
10 changes: 10 additions & 0 deletions 1-exercises/F-for-of-loop/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,13 @@ let tubeStations = [

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

for (let i = 0; i < tubeStations.length; i++) {
const index = tubeStations[i];
console.log(index);
}
let capture = ""
for (let i = 0; i < str.length; i++) {
capture += str[i];
}
console.log(capture.toUpperCase());
6 changes: 5 additions & 1 deletion 2-mandatory/1-weather-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@

function getTemperatureReport(cities) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You are very close to finishing this exercise.

Please think over it and modify your solution in the way that You are going to pass these test cases:
✕ should return a temperature report for the user's cities (10 ms)
✕ should return a temperature report for the user's cities (alternate input) (1 ms)

Tip: Check what exactly you are pushing in line 19 to the array.

// TODO
let temperature = [];
for (let i = 0; i < cities.length; i++) {
tem.push(`The temperature in ${cities[i]} is ${temperatureService(cities[i])} degrees`);
}
return temperature;
}


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

Expand Down
6 changes: 5 additions & 1 deletion 2-mandatory/2-retrying-random-numbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +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
19 changes: 19 additions & 0 deletions 2-mandatory/3-financial-times.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/
function potentialHeadlines(allArticleTitles) {
// TODO
const article = allArticleTitles.filter((article) => article.length <= 65);
return article;
}

/*
Expand All @@ -15,15 +17,26 @@ function potentialHeadlines(allArticleTitles) {
*/
function titleWithFewestWords(allArticleTitles) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You are so close to solving the last two test cases.
Please improve your solution and pass the last two requirements:
✕ should return the title with the fewest words (1 ms)
✕ should return the average number of characters in a headline

// 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!
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
}

/*
Expand All @@ -32,6 +45,12 @@ function headlinesWithNumbers(allArticleTitles) {
*/
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
15 changes: 15 additions & 0 deletions 2-mandatory/4-stocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [
*/
function getAveragePrices(closingPricesForAllStocks) {
// TODO
return closingPricesForAllStocks.map((priceArr) => {
return Number(
(priceArr.reduce((tot, num) => tot + num) / priceArr.length).toFixed(2)
);
});
}

/*
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));
});
}

/*

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Please finish last part of the exercise:

function highestPriceDescriptions(closingPricesForAllStocks, stocks) {
    // TODO
}

Expand All @@ -65,6 +73,13 @@ function getPriceChanges(closingPricesForAllStocks) {
*/
function highestPriceDescriptions(closingPricesForAllStocks, stocks) {
// TODO
let highestPriceDescriptions = [];
for (let i = 0; i < closingPricesForAllStocks.length; i++) {
highestPriceDescriptions.push(`The highest price of ${stocks[i].toUpperCase()} in the last 5 days was ${Math.max(...closingPricesForAllStocks[i]
).toFixed(2)}`
);
}
return highestPriceDescriptions;
}


Expand Down