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
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
8 changes: 7 additions & 1 deletion 1-exercises/A-undefined/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,24 @@ function sayHello() {
let message = "Hello";
}

// In the above example we wish to use the name that the user provides to greet them

let hello = sayHello();
console.log(hello);

// in the above example we need the users name to to log the function


// Example 3
function sayHelloToUser(user) {
console.log(`Hello ${user}`);
}

sayHelloToUser();

// the user needs to input username for the greeting Hello user to be printed

// Example 4
let arr = [1,2,3];
console.log(arr[3]);

// arr 3 is undefined as the array only currently goes to 2. Once the array another value is added to the array it will be printed in the terminal
11 changes: 10 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,16 @@
*/

function evenNumbers(n) {
// TODO
let i = 0;
let arrayEven = [];
while (arrayEven.length < n) {
if (i % 2 === 0) {
arrayEven.push(i);
}
i++;
}
return console.log(arrayEven.toString());

}

evenNumbers(3); // should output 0,2,4
Expand Down
9 changes: 8 additions & 1 deletion 1-exercises/C-while-loop-with-array/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@ const BIRTHDAYS = [
"November 15th"
];


function findFirstJulyBDay(birthdays) {
// TODO
let i = 0;
while (i < birthdays.length){
if(birthdays[i].includes(`July`)){
return birthdays[i];
}
i++;
}
}

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

Using a do-while loop, write a function which returns the sum of the first n even numbers (starting from 0)
*/

let i = 0;
let total = 0;
let evenSum = []
function evenNumbersSum(n) {
// TODO
do{
if(i % 2 === 0){
evenSum.push(i);
total = total + i;
}
i ++;
} while (evenSum.length < n)
return total;
}

console.log(evenNumbersSum(3)); // should output 6
Expand Down
2 changes: 1 addition & 1 deletion 1-exercises/E-for-loop/exercise1.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

// Change the below code to use a for loop instead of a while loop.
let i = 0;
while(i < 26) {
for( i = 0; i < 26; i + 1 ) {
console.log(String.fromCharCode(97 + i));
i++;
}
Expand Down
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 @@ -11,6 +11,14 @@ let tubeStations = [
"Tottenham Court Road"
];

for (const value of tubeStations) {
console.log(value);
}


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

for (const letter of str) {
console.log(letter.toUpperCase())
};
10 changes: 9 additions & 1 deletion 2-mandatory/1-weather-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,17 @@
*/

function getTemperatureReport(cities) {
// TODO
// i need to create a new array to push the items to
let reportArray =[];
for (const element of cities) {
if(temperatureService(element)){
reportArray.push(`The temperature in ${element} is ${temperatureService(element)} degrees`)
}
}return reportArray
}




/* ======= 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 @@ -10,7 +10,11 @@ function generateRandomNumber() {
}

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

/* ======= TESTS - DO NOT MODIFY ===== */
Expand Down
33 changes: 27 additions & 6 deletions 2-mandatory/3-financial-times.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@
The home page of the web site has a headline section, which only has space for article titles which are 65 characters or less.
Implement the function below, which will return a new array containing only article titles which will fit.
*/
function potentialHeadlines(allArticleTitles) {
// TODO
function potentialHeadlines(allArticleTitles)
{
let articleArray = [];
{
for (const element of allArticleTitles) {
if (element.length <= 65);
articleArray.push(element)
}
}return articleArray
}

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

/*
Expand All @@ -24,15 +32,28 @@ function titleWithFewestWords(allArticleTitles) {
*/
function headlinesWithNumbers(allArticleTitles) {
// TODO
{
let allArticleTitlesNew = []
for (const element of allArticleTitles) {
if (element.includes(Number)){
allArticleTitlesNew.push(element)
}
return allArticleTitlesNew
}
}

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



Expand Down
29 changes: 28 additions & 1 deletion 2-mandatory/4-stocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,20 @@ const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [
Functions can help with this!
*/
function getAveragePrices(closingPricesForAllStocks) {
// TODO
let averageArray = [];
let averagePrice;

for (const array of closingPricesForAllStocks) {
let num = 0;
for (const number of array) {
num += number;
}

averagePrice = num / 5;
averageArray.push(parseFloat(averagePrice.toFixed(2)));
}
return averageArray;

}

/*
Expand All @@ -49,6 +62,12 @@ function getAveragePrices(closingPricesForAllStocks) {
*/
function getPriceChanges(closingPricesForAllStocks) {
// TODO
let priceChanges = [];
for (const array of closingPricesForAllStocks) {
let comparePrices = (array.at(0) - array.at(-1)) * -1 ;
priceChanges.push(parseFloat(comparePrices.toFixed(2)))
}
return priceChanges;
}

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


Expand Down