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
11 changes: 11 additions & 0 deletions 1-exercises/A-undefined/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
let a;
console.log(a);

//ANSWER the variable A had no value, if we tested on the terminal show "undefind" (no value in it)


// Example 2
function sayHello() {
Expand All @@ -22,6 +24,9 @@ function sayHello() {
let hello = sayHello();
console.log(hello);

// ANSWER here the funtion is with a variable (sayHello). When we call the funtion this this should call the variable instead the message OR
//we can also call the message but it should be iside "" STRINGS


// Example 3
function sayHelloToUser(user) {
Expand All @@ -30,7 +35,13 @@ function sayHelloToUser(user) {

sayHelloToUser();

// Again USER is not defined with a VALUE and will only print the message in STRINGS "" (HELLO)



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

// in JS it counts from 0. For this example if we want the last digit we call it number 2,
//then it will show number 3.
15 changes: 13 additions & 2 deletions 1-exercises/B-while-loop/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,23 @@

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 result = [];
let i = 0;
while (i < n) {
result.push(i*2);
i++
}
console.log(result.join());
}

evenNumbers(3); // should output 0,2,4
evenNumbers(0); // should output nothing
evenNumbers(10); // should output 0,2,4,6,8,10,12,14,16,18




14 changes: 12 additions & 2 deletions 1-exercises/C-while-loop-with-array/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,18 @@ const BIRTHDAYS = [
"November 15th"
];

function findFirstJulyBDay(birthdays) {

// TODO
}

let i = 0;
while (i < BIRTHDAYS.length) {
if (BIRTHDAYS[i].startsWith("July")){
return BIRTHDAYS[i];
}
i++;
}



console.log(findFirstJulyBDay(BIRTHDAYS)); // should output "July 11th"
console.log("testing");
8 changes: 7 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,13 @@
*/

function evenNumbersSum(n) {
// TODO
let sum = 0;
let i = 0;
do {
sum += (i*2);
i++;
} while (i < n);
return sum;
}

console.log(evenNumbersSum(3)); // should output 6
Expand Down
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 (i =0; i < 26; i++)
console.log(String.fromCharCode(97 + i));
i++;
}
Expand Down
4 changes: 4 additions & 0 deletions 1-exercises/E-for-loop/exercise2.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,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
7 changes: 7 additions & 0 deletions 2-mandatory/1-weather-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@

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


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,8 +11,14 @@ function generateRandomNumber() {

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


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

test("Returned value should always be greater than 50", () => {
Expand Down
24 changes: 24 additions & 0 deletions 2-mandatory/3-financial-times.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,27 @@
*/
function potentialHeadlines(allArticleTitles) {
// TODO
let headline = []
for (article of allArticleTitles){
if (article.length > 50 ) headline.push(article) ;
}
return headline;
}


/*
The editor of the FT likes short headlines with only a few words!
Implement the function below, which returns the title with the fewest words.
(you can assume words will always be seperated by a space)
*/
function titleWithFewestWords(allArticleTitles) {
// TODO
let lowestWords = [];
for (let i = 0; i< allArticleTitles.length; i++) {
lowestWords.push(allArticleTitles[i].split(' ').length)
}
return allArticleTitles[lowestWords.indexOf(Math.min(...lowestWords))]

}

/*
Expand All @@ -24,6 +36,13 @@ function titleWithFewestWords(allArticleTitles) {
*/
function headlinesWithNumbers(allArticleTitles) {
// TODO
let numberArray = [];
for (let article of allArticleTitles) {
if (/[0-9]/.test(article) === true) {
numberArray.push(article);
}
}
return numberArray;
}

/*
Expand All @@ -32,6 +51,11 @@ function headlinesWithNumbers(allArticleTitles) {
*/
function averageNumberOfCharacters(allArticleTitles) {
// TODO
let averageCharacter = [];
for (let i = 0; i < allArticleTitles.length; i++) {
averageCharacter += allArticleTitles[i].length
}
return Math.round(averageCharacter / allArticleTitles.length)
}


Expand Down
27 changes: 27 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 price = [];
for (let individualArray of closingPricesForAllStocks) {
price.push(individualAverage(individualArray));
}
return price;

}
function individualAverage(array) {
let total = 0;
for (let closing of array) {
total += closing;
}
return Number(total / array.length).toFixed(2);
}

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

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


Expand Down