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

// Example 1
// Example 1 - The reason this would return and undefined error is due to the variable 'a' not having a value assigned to it.
let a;
console.log(a);


// Example 2
// Example 2 - This would be undefined as the function does not have a parameter.
function sayHello() {
let message = "Hello";
}
Expand All @@ -23,14 +23,14 @@ let hello = sayHello();
console.log(hello);


// Example 3
// Example 3 - This will be undefined as no user has been entered.
function sayHelloToUser(user) {
console.log(`Hello ${user}`);
}

sayHelloToUser();


// Example 4
// Example 4 - This will be undefined as there is no 3rd index.
let arr = [1,2,3];
console.log(arr[3]);
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
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
2 changes: 2 additions & 0 deletions 1-exercises/C-while-loop-with-array/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const BIRTHDAYS = [

function findFirstJulyBDay(birthdays) {
// TODO
const findFirstJulyBDay = birthdays.filter((bDay) => bDay.startWith("July"))
return findFirstJulyBDay[0]
}

console.log(findFirstJulyBDay(BIRTHDAYS)); // should output "July 11th"
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) {
// 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: 2 additions & 2 deletions 1-exercises/E-for-loop/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

// 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.
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 @@ -27,7 +27,9 @@ 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
8 changes: 8 additions & 0 deletions 1-exercises/F-for-of-loop/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,13 @@ let tubeStations = [
];


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++){

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cool, good work

console.log(str[i].toUpperCase())
}

6 changes: 6 additions & 0 deletions 2-mandatory/1-weather-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,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;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Your function is undefined @MarvinLeeMarshall



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

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

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

/*
Expand All @@ -15,6 +16,12 @@ function potentialHeadlines(allArticleTitles) {
*/
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 @@ -24,14 +31,23 @@ function titleWithFewestWords(allArticleTitles) {
*/
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 total = 0;
for (let title of allArticleTitles) {
total += title.length;
}
let average = total / allArticleTitles.length;
return Math.round(average);
}


Expand Down
32 changes: 32 additions & 0 deletions 2-mandatory/4-stocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@ const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [
*/
function getAveragePrices(closingPricesForAllStocks) {
// TODO
let stockPriceAverage = [];
for (let i = 0; i < closingPricesForAllStocks.length; i++) {
let stockPriceTotal = 0;
let stockPrice = closingPricesForAllStocks[i];
for (let j = 0; j < stockPrice.length; j++) {
stockPriceTotal += stockPrice[j];
}
stockPriceAverage.push(
parseFloat((stockPriceTotal / stockPrice.length).toFixed(2))
);
}
return stockPriceAverage;

}

/*
Expand All @@ -49,6 +62,14 @@ function getAveragePrices(closingPricesForAllStocks) {
*/
function getPriceChanges(closingPricesForAllStocks) {
// TODO
changedPrice = [];
for (const price of closingPricesForAllStocks) {
let priceDifference = parseFloat(
(price[price.length - 1] - price[0]).toFixed(2)
);
changedPrice.push(priceDifference);
}
return changedPrice;
}

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

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 Marvin: There is an "Uncaught Reference Error: closingPricesForAllStocks is not defined"

...closingPricesForAllStocks[i]
).toFixed(2)}`
);
}
return highestPriceForEachStock;
}


Expand Down