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

// a doesnt have a any value;


// Example 2
function sayHello() {
let message = "Hello";
}


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

//in line 25 hello is calling the function instead of setting it to hello;


// Example 3
function sayHelloToUser(user) {
Expand Down
4 changes: 2 additions & 2 deletions 1-exercises/B-array-literals/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
Declare some variables assigned to arrays of values
*/

let numbers = []; // add numbers from 1 to 10 into this array
let mentors; // Create an array with the names of the mentors: Daniel, Irina and Rares
let numbers = [1,2,3,4,5,6,7,8,9,10]; // add numbers from 1 to 10 into this array
let mentors = [" Daniel", "Irina", "Rares"] // Create an array with the names of the mentors: Daniel, Irina and Rares

/*
DO NOT EDIT BELOW THIS LINE
Expand Down
4 changes: 2 additions & 2 deletions 1-exercises/C-array-get-set/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
*/

function first(arr) {
return; // complete this statement
return arr[0]
}

function last(arr) {
return; // complete this statement
return arr[arr.length - 1];
}

/*
Expand Down
5 changes: 5 additions & 0 deletions 1-exercises/C-array-get-set/exercises2.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@

let numbers = [1, 2, 3]; // Don't change this array literal declaration

numbers.push(4);
numbers[0] = 1;

/*
DO NOT EDIT BELOW THIS LINE
--------------------------- */
console.log(numbers);

/*

EXPECTED RESULT
---------------
[1, 2, 3, 4]

*/
4 changes: 4 additions & 0 deletions 1-exercises/D-for-loop/exercise.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
30 changes: 23 additions & 7 deletions 1-exercises/E-while-loop-with-array/exercise.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
/*
Loops can be useful when working with arrays.
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.
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",
"January 7th",
"February 12th",
"April 3rd",
"April 5th",
"May 3rd",
"July 11th",
Expand All @@ -16,8 +18,22 @@ const BIRTHDAYS = [
"November 15th"
];

function findFirstJulyBDay(birthdays) {
// TODO
function findFirstJulyBDay(parameter) {

let currentIndex = 0;

while (currentIndex < parameter.length){
if (parameter[currentIndex].includes("July")) {
return parameter[currentIndex]
}else {
currentIndex++;
}
// console.log(parameter[currentIndex])
}
return "no July here"

}



console.log(findFirstJulyBDay(BIRTHDAYS)); // should output "July 11th"
13 changes: 9 additions & 4 deletions 2-mandatory/1-weather-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@
For example, "The temperature in London is 10 degrees"
- Hint: you can call the temperatureService function from your function
*/

function getTemperatureReport(cities) {
// TODO
}

const reports = [];

for (let i = 0; i < cities.length; i++) {
const temperature = temperatureService(cities[i]);
reports.push(`The temperature in ${cities[i]} is ${temperature} degrees`);
}

return reports;
}

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

Expand Down
62 changes: 52 additions & 10 deletions 2-mandatory/2-financial-times.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
/*
Imagine you are working on the Financial Times web site! They have a list of article titles stored in an array.
Imagine you are working on the Financial Times web site!

They have a list of article titles stored in an array.

The home page of the web site has a headline section, which only has space for article titles
which are 65 characters or less.

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
const container = []

for (let i = 0; i < allArticleTitles.length; i++) {
const titleContainter = allArticleTitles[i];
if (titleContainter.length <= 65) {
container.push(titleContainter)
}


}

return container

}

/*
Expand All @@ -14,25 +30,51 @@ function potentialHeadlines(allArticleTitles) {
(you can assume words will always be seperated by a space)
*/
function titleWithFewestWords(allArticleTitles) {
// TODO
}

let fewestWords = allArticleTitles[0];

for (let i = 1; i < allArticleTitles.length; i++) {
if (allArticleTitles[i].split(' ').length < fewestWords.split(' ').length) {
fewestWords = allArticleTitles[i];
}
}
return fewestWords;
}
/*
The editor of the FT has realised that headlines which have numbers in them get more clicks!
Implement the function below to return a new array containing all the headlines which contain a number.
(Hint: remember that you can also loop through the characters of a string if you need to)
*/
function headlinesWithNumbers(allArticleTitles) {
// TODO
}
const container = [];

for (let i = 0; i < allArticleTitles.length; i++) {
const title = allArticleTitles[i];
for (let j = 0; j < title.length; j++) {
if (!isNaN(parseInt(title[j]))) {
container.push(title);
break;
}
}
}

return container;
}

/*
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 chars = 0;

for (let i = 0; i < allArticleTitles.length; i++) {
chars += allArticleTitles[i].length;
}

const averageChars = chars / allArticleTitles.length;

return Math.round(averageChars);
}



Expand Down
49 changes: 43 additions & 6 deletions 2-mandatory/3-stocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,23 @@ const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [
Functions can help with this!
*/
function getAveragePrices(closingPricesForAllStocks) {
// TODO
}
const result = [];

for (let i = 0; i < closingPricesForAllStocks.length; i++) {
const stockPrices = closingPricesForAllStocks[i];
let sum = 0;

for (let j = 0; j < stockPrices.length; j++) {
sum += stockPrices[j];
}

const average = sum / stockPrices.length;
result.push(parseFloat(average.toFixed(2)));
}

return result;
}


/*
We also want to see what the change in price is from the first day to the last day for each stock.
Expand All @@ -48,8 +63,19 @@ 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
}
const priceChanges = [];

for (let i = 0; i < closingPricesForAllStocks.length; i++) {
const stockPrices = closingPricesForAllStocks[i];
const firstDayPrice = stockPrices[0];
const lastDayPrice = stockPrices[stockPrices.length - 1];
const priceChange = lastDayPrice - firstDayPrice;
priceChanges.push(parseFloat(priceChange.toFixed(2)));
}

return priceChanges;
}


/*
As part of a financial report, we want to see what the highest price was for each stock in the last 5 days.
Expand All @@ -64,8 +90,19 @@ function getPriceChanges(closingPricesForAllStocks) {
The price should be shown with exactly 2 decimal places.
*/
function highestPriceDescriptions(closingPricesForAllStocks, stocks) {
// TODO
}
const descriptions = [];

for (let i = 0; i < stocks.length; i++) {
const stock = stocks[i];
const closingPrices = closingPricesForAllStocks[i];
const highestPrice = Math.max(...closingPrices).toFixed(2);

descriptions.push(`The highest price of ${stock.toUpperCase()} in the last 5 days was ${highestPrice}`);
}

return descriptions;
}



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