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
4 changes: 4 additions & 0 deletions 1-exercises/A-undefined/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@
// Example 1
let a;
console.log(a);
//the value is missing



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


let hello = sayHello();
console.log(hello);
Expand Down
13 changes: 10 additions & 3 deletions 1-exercises/B-while-loop/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@
Using a while loop, complete the function below so it logs (using console.log) the first n even numbers as a comma-seperated string.
The list of numbers should start with 0. n is being passed in as a parameter.
*/

function evenNumbers(n) {
// TODO
}
let arrayOfEvenNumbers = [];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hi, Emeka I hope you are ok, I reviewed your answer and it is correct and functional.

let i = 0;
while (n > arrayOfEvenNumbers.length) {
if (i % 2 === 0) {
arrayOfEvenNumbers.push(i);
}
i++;
}
console.log(arrayOfEvenNumbers);
}

evenNumbers(3); // should output 0,2,4
evenNumbers(0); // should output nothing
Expand Down
31 changes: 15 additions & 16 deletions 1-exercises/C-while-loop-with-array/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@
In the below example, imagine we've defined an array holding the birthdays of your closest friends.
Use a while loop to search through the array until you find the first birthday in July, then return that birthday from the function.
*/

const BIRTHDAYS = [
"January 7th",
"February 12th",
"April 3rd",
"April 5th",
"May 3rd",
"July 11th",
"July 17th",
"September 28th",
"November 15th"
];
while (condition) {
const BIRTHDAYS = [
"January 7th",
"February 12th",
"April 3rd",
"April 5th",
"May 3rd",
"July 11th",
"July 17th",
"September 28th",
"November 15th"
];

}

function findFirstJulyBDay(birthdays) {
// TODO
}

console.log(findFirstJulyBDay(BIRTHDAYS)); // should output "July 11th"
return (birthdays
9 changes: 3 additions & 6 deletions 1-exercises/D-do-while/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
Using a do-while loop, write a function which returns the sum of the first n even numbers (starting from 0)
*/

function evenNumbersSum(n) {
// TODO
for (let i = 0; i < 11; i++) {
console.log(i*9);
}

console.log(evenNumbersSum(3)); // should output 6
console.log(evenNumbersSum(0)); // should output 0
console.log(evenNumbersSum(10)); // should output 90
// should output 90
1 change: 1 addition & 0 deletions 1-exercises/E-for-loop/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,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++) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is your for loop nested inside the while loop? How come you have done it like this?

console.log(String.fromCharCode(97 + i));
i++;
}
Expand Down
5 changes: 4 additions & 1 deletion 1-exercises/E-for-loop/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ 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
15 changes: 11 additions & 4 deletions 1-exercises/F-for-of-loop/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@

// TODO Use a for-of loop to output each of the tube stations below.
let tubeStations = [
"Aldgate",
"Baker Street",

"Picadilly Circus",
"Oxford Street",
"Tottenham Court Road"

];

for (stations of tubeStations){
console.log(stations)
}



// TODO Use a for-of loop to capitalise and output each letter in the string seperately.

let str = "codeyourfuture";
for (char of str){
console.log(char.toUpperCase())
}
3 changes: 3 additions & 0 deletions 2-mandatory/1-weather-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@

function getTemperatureReport(cities) {
// TODO
let cityTemperatures = cities.map(city => `The temperature in ${city} is ${temperatureService(city)} degrees`)
return cityTemperatures
}



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

function temperatureService(city) {
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
}
do {
value = generateRandomNumber()
} while( value <= 50)
return value
}

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

Expand Down
22 changes: 21 additions & 1 deletion 2-mandatory/3-financial-times.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
Implement the function below, which will return a new array containing only article titles which will fit.
*/
function potentialHeadlines(allArticleTitles) {
let selectedHeadings = allArticleTitles.filter(article => article.length <= 65);
return selectedHeadings;
}
// TODO
}

Expand All @@ -14,7 +17,9 @@ function potentialHeadlines(allArticleTitles) {
(you can assume words will always be seperated by a space)
*/
function titleWithFewestWords(allArticleTitles) {
// TODO
let smallestArticle = allArticleTitles.reduce((initial, next) => (initial.length < next.length)? initial : next);
return smallestArticle;
}
}

/*
Expand All @@ -24,6 +29,15 @@ function titleWithFewestWords(allArticleTitles) {
*/
function headlinesWithNumbers(allArticleTitles) {
// TODO
let selectedHeadings = allArticleTitles.filter((element) => {
for (let i = 0; i < element.length; i++) {
if (parseInt(element[i])) {
return true;
}
}
return false;
});
return selectedHeadings;
}

/*
Expand All @@ -33,6 +47,12 @@ function headlinesWithNumbers(allArticleTitles) {
function averageNumberOfCharacters(allArticleTitles) {
// TODO
}
let totalCharacters = allArticleTitles.reduce((acc, curr) => acc + (curr.length), 0);

let average = totalCharacters / (allArticleTitles.length)

return Math.round(average);
}



Expand Down
27 changes: 26 additions & 1 deletion 2-mandatory/4-stocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [
Functions can help with this!
*/
function getAveragePrices(closingPricesForAllStocks) {
// TODO
const average = closingPricesForAllStocks.map((arr) =>
arr.reduce((acc, curr) => acc + curr / arr.length, 0)
);
const roundedStockPrices = average.map((element) => parseFloat(element.toFixed(2)));
return roundedStockPrices;

}

/*
Expand All @@ -49,6 +54,13 @@ function getAveragePrices(closingPricesForAllStocks) {
*/
function getPriceChanges(closingPricesForAllStocks) {
// TODO
let changeInStocks = closingPricesForAllStocks.map(
(arr) => arr[arr.length - 1] - arr[0]
);

changeInStocks = changeInStocks.map((element) => parseFloat(element.toFixed(2)));

return changeInStocks;
}

/*
Expand All @@ -66,6 +78,19 @@ function getPriceChanges(closingPricesForAllStocks) {
function highestPriceDescriptions(closingPricesForAllStocks, stocks) {
// TODO
}
let arrayOfHighestPrices = closingPricesForAllStocks.map((arr) =>
arr.reduce((acc, curr) => {
return acc > curr ? acc : curr;
})
);
let stocksDescription = [];
for (let i = 0; i< arrayOfHighestPrices.length; i++){
stocksDescription.push(
`The highest price of ${(stocks[i]).toUpperCase()} in the last 5 days was ${(arrayOfHighestPrices[i]).toFixed(2)}`
);
}
return stocksDescription



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