Skip to content
This repository was archived by the owner on Jan 14, 2024. It is now read-only.

London_10- Danny Romero-JS-Core-1-Coursework-week3 #269

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
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
9 changes: 5 additions & 4 deletions 1-exercises/A-undefined/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@

// Example 1
let a;
console.log(a);
console.log(a); //it will be undefined because it does not have any value


// Example 2
function sayHello() {
let message = "Hello";
let message = "Hello"; //hello is not a string in console.log, so the program reads it as variable, but "hello" doesn't exist.
}

let hello = sayHello();
Expand All @@ -28,9 +28,10 @@ function sayHelloToUser(user) {
console.log(`Hello ${user}`);
}

sayHelloToUser();
sayHelloToUser(); //when calling function we don't pass any value for parameter user



// Example 4
let arr = [1,2,3];
console.log(arr[3]);
console.log(arr[3]); //element in arr with index 3 doesn't exist. There only 0, 1, 2.
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", "Irina"]// Create an array with the names of the mentors: Daniel, Irina and Rares

/*
DO NOT EDIT BELOW THIS LINE
Expand Down
8 changes: 4 additions & 4 deletions 1-exercises/C-array-get-set/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
Complete the functions below to get the first and last values from the array
*/

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

function last(arr) {
return; // complete this statement
function last(names) {
return[3]; // complete this statement
}

/*
Expand Down
4 changes: 2 additions & 2 deletions 1-exercises/C-array-get-set/exercises2.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
- change the first value in the array to the number 1
*/

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

let numbers = [2, 3, 4]; // Don't change this array literal declaration
numbers[0] = 1;
/*
DO NOT EDIT BELOW THIS LINE
--------------------------- */
Expand Down
5 changes: 5 additions & 0 deletions 1-exercises/D-for-loop/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,8 @@ Jane Austen is 41 years old
Bell Hooks is 63 years old
Yukiko Motoya is 49 years old
*/
const AGES = [59, 40, 41, 63, 49];

for (let i = 0; i < WRITERS.length; i++) {
console.log(WRITERS[i] + " is " + AGES[i] + " years old");
}
16 changes: 13 additions & 3 deletions 1-exercises/E-while-loop-with-array/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,19 @@ const BIRTHDAYS = [
"September 28th",
"November 15th"
];
//let count = 0;

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

console.log(findFirstJulyBDay(BIRTHDAYS)); // should output "July 11th"
// should output "July 11th"
}
20 changes: 18 additions & 2 deletions 2-mandatory/1-weather-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,25 @@

function getTemperatureReport(cities) {
// TODO
}

let arr = [];
Copy link
Contributor

@moneyinthesky moneyinthesky Mar 15, 2023

Choose a reason for hiding this comment

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

Your implementation here looks good 👍
You are adding the value returned by temperatureService to the array arr.
The question wants you to take this value, and put it into a string - like "The temperature in London is 10 degrees".
Can you think of how to create a string like this using the value you get back from the temperatureService?
One idea is to use template literals in JavaScript: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals
When you have created this string - you could add that to the array instead 😄

let degree = 0;
let cityDegree = "";
for (let i = 0; i < cities.length; i++) {
degree = temperatureService(cities[i]);

arr.push(cityDegree);
}
return arr;

} let arr = [];
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like you have the same code copied twice here, maybe this was an accident?

let degree = 0;
let cityDegree = "";
for (let i = 0; i < cities.length; i++) {
degree = temperatureService(cities[i]);
cityDegree = `The temperature in ${cities[i]} is ${degree} degrees`;
arr.push(cityDegree);
}
return arr
/* ======= TESTS - DO NOT MODIFY ===== */

function temperatureService(city) {
Expand Down
41 changes: 41 additions & 0 deletions 2-mandatory/2-financial-times.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@
*/
function potentialHeadlines(allArticleTitles) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like you have the same function name defined twice here? function potentialHeadlines(allArticleTitles) {

// TODO
function potentialHeadlines(allArticleTitles) {
// TODO
let shortArticles = [];
for (let article of allArticleTitles) {
if (article.length <= 65) {
shortArticles.push(article);
}
}
return shortArticles;
}

}

/*
Expand All @@ -15,6 +26,14 @@ function potentialHeadlines(allArticleTitles) {
*/
function titleWithFewestWords(allArticleTitles) {
// TODO
const myArray = [];
for (let article of allArticleTitles) {
myArray.push(article.split(" "));
}
let result = myArray.reduce(function (a,b) {
return a.length <= b.length ? a : b;
});
return allArticleTitles[myArray.indexOf(result)];
}

/*
Expand All @@ -24,18 +43,40 @@ function titleWithFewestWords(allArticleTitles) {
*/
function headlinesWithNumbers(allArticleTitles) {
// TODO
let countArray = [];
for (article of allArticleTitles) {
countArray.push(article.length);
}
let sum = 0;
for (let i = 0; i < countArray.length; i++) {
sum += countArray[i];
}
return Math.round(sum / countArray.length);
}




/*
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 countArray = [];
for (article of allArticleTitles) {
countArray.push(article.length);
}
let sum = 0;
for (let i = 0; i < countArray.length; i++) {
sum += countArray[i];
}
return Math.round(sum / countArray.length);
}




/* ======= List of Articles - DO NOT MODIFY ===== */
const ARTICLE_TITLES = [
"Streaming wars drive media groups to spend more than $100bn on new content",
Expand Down
28 changes: 28 additions & 0 deletions 2-mandatory/3-stocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,16 @@ const CLOSING_PRICES_LAST_5_DAYS_FOR_ALL_STOCKS = [
*/
function getAveragePrices(closingPricesForAllStocks) {
// TODO
let averageOfWeek = [];
//looping through array of arrays and calling findAveragePrice method on each array
for (let averageOfWeek of closingPricesForAllStocks) {
averageOfWeek.push(findAveragePrice(averageOfWeek));
}
return averageOfWeek;
}



/*
We also want to see what the change in price is from the first day to the last day for each stock.
Implement the below function, which
Expand All @@ -49,6 +57,13 @@ function getAveragePrices(closingPricesForAllStocks) {
*/
function getPriceChanges(closingPricesForAllStocks) {
// TODO
let result =[];

for( let i = 0; i< closingPricesForAllStocks.length; i++) {
let diff =0;
diff = closingPricesForAllStocks[i][4] - closingPricesForAllStocks[i][0];
result.push(parseFloat(diff.toFixed(2)));
}
}

/*
Expand All @@ -65,6 +80,19 @@ function getPriceChanges(closingPricesForAllStocks) {
*/
function highestPriceDescriptions(closingPricesForAllStocks, stocks) {
// TODO

let arr = [];
for (let i = 0; i < closingPricesForAllStocks.length; i++) {
arr.push(
`The highest price of ${stocks[
i
].toUpperCase()} in the last 5 days was ${Math.max(
...closingPricesForAllStocks[i]
).toFixed(2)}`
);
}
return arr;

}


Expand Down