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
10 changes: 9 additions & 1 deletion 1-exercises/B-while-loop/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@
*/

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
7 changes: 6 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,12 @@ const BIRTHDAYS = [
];

function findFirstJulyBDay(birthdays) {
// TODO
let i = 0
while (i<= BIRTHDAYS.length) {
let a = birthdays[5]
console.log(a[i])
i++
}
}

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

function evenNumbersSum(n) {
// TODO
i=0
do {
console.log(i)
i++
} while (i<=5);
}

console.log(evenNumbersSum(3)); // should output 6
Expand Down
8 changes: 4 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,9 @@


// 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++;

for(let i = 0; i < 26; i++) {
console.log(String.fromCharCode(97 + i));
i++;
}
// The output shouldn't change.
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 @@ -26,7 +26,9 @@ const AGES = [
49
];

// 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
7 changes: 6 additions & 1 deletion 1-exercises/F-for-of-loop/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ 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())
}
7 changes: 6 additions & 1 deletion 2-mandatory/1-weather-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
*/

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


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
let i = 0
do {
i = generateRandomNumber()
} while (i<50);
return i
}

/* ======= TESTS - DO NOT MODIFY ===== */
Expand Down
18 changes: 14 additions & 4 deletions 2-mandatory/3-financial-times.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Implement the function below, which will return a new array containing only article titles which will fit.
*/
function potentialHeadlines(allArticleTitles) {
// TODO
return allArticleTitles.filter((article) => article.length <= 65)
}

/*
Expand All @@ -14,7 +14,12 @@ function potentialHeadlines(allArticleTitles) {
(you can assume words will always be seperated by a space)
*/
function titleWithFewestWords(allArticleTitles) {
// TODO
let result = allArticleTitles[0]
for (let i = 0; i < allArticleTitles.length; i++) {
if (allArticleTitles[i].split(' ').length < result.split(' ').length)
result = allArticleTitles[i];
}
return result
}

/*
Expand All @@ -23,15 +28,20 @@ function titleWithFewestWords(allArticleTitles) {
(Hint: remember that you can also loop through the characters of a string if you need to)
*/
function headlinesWithNumbers(allArticleTitles) {
// TODO
return allArticleTitles.filter((article) => article.match(/(\d+)/));
}

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


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

/*
Expand All @@ -48,7 +50,9 @@ function getAveragePrices(closingPricesForAllStocks) {
The price change value should be rounded to 2 decimal places, and should be a number (not a string)
*/
function getPriceChanges(closingPricesForAllStocks) {
// TODO
return closingPricesForAllStocks.map(priceArr => {
return Number((priceArr[priceArr.length - 1] - priceArr[0]).toFixed(2));
})
}

/*
Expand Down