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

London10-StellaDelMar_RodriguezFernandez-JavaScript-Core-1-Coursework-Week3 #278

Open
wants to merge 3 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
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"cSpell.words": [
"Paulo"
]
}
47 changes: 32 additions & 15 deletions 2-mandatory/1-weather-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,51 @@
Imagine we're making a weather app!

We have a list of cities that the user wants to track.
We also already have a temperatureService function which will take a city as a parameter and return a temparature.
We also already have a temperatureService function
which will take a city as a parameter and return a
temperature.

Implement the function below:
- take the array of cities as a parameter
- return an array of strings, which is a statement about the temperature of each city.
For example, "The temperature in London is 10 degrees"
- Hint: you can call the temperatureService function from your function
- return an array of strings, which is a
statement about the temperature of each city.
For example, "The temperature in London is
10 degrees"
- Hint: you can call the temperatureService
function from your function
*/

//temperatureService
//temperature

//const cities = [ "London", "Paris", "Barcelona", "Dubai", "Mumbai", "São Paulo", "Lagos"];

function getTemperatureReport(cities) {
// TODO
let result = [];
for (let city of cities) {
let temperature = temperatureService(city);
result.push(`The temperature in ${city} is ${temperature}°C`);
}
return result;
}
//console.log(`The temperature in ${"city"} is ${temperature}°C`);
// TODO


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

function temperatureService(city) {
let temparatureMap = new Map();

temparatureMap.set('London', 10);
temparatureMap.set('Paris', 12);
temparatureMap.set('Barcelona', 17);
temparatureMap.set('Dubai', 27);
temparatureMap.set('Mumbai', 29);
temparatureMap.set('São Paulo', 23);
temparatureMap.set('Lagos', 33);
let temperatureMap = new Map();

temperatureMap.set('London', 10);
temperatureMap.set('Paris', 12);
temperatureMap.set('Barcelona', 17);
temperatureMap.set('Dubai', 27);
temperatureMap.set('Mumbai', 29);
temperatureMap.set('São Paulo', 23);
temperatureMap.set('Lagos', 33);

return temparatureMap.get(city);
return temperatureMap.get(city);
}

test("should return a temperature report for the user's cities", () => {
Expand Down
84 changes: 66 additions & 18 deletions 2-mandatory/2-financial-times.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,87 @@
/*
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.
Implement the function below, which will return a new array containing only article titles which will fit.
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.
*/
//if length is 65 or more, to include.

function potentialHeadlines(allArticleTitles) {
// TODO
}
const thisArticle = [];
for (const title of allArticleTitles){
if (title.length <= 65){
thisArticle.push(title);
}
}return thisArticle;
} //console.log(thisArticle);

/*
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)
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 separated
by a space)
*/
function titleWithFewestWords(allArticleTitles) {
// TODO
// let headlines = "";
//let shortestHeadLine = headlines -1;
for (let headlines of allArticleTitles){
if (shortestHeadLine === "" || headlines.length < shortestHeadLine.length){
shortestHeadLine = headlines; }

}
return shortestHeadLine;
}
//console.log(shortestHeadLine);



/*
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)
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)
*/
//break
function headlinesWithNumbers(allArticleTitles) {
// TODO
}
let articlesContainingNumber = [];
for (const headline of allArticleTitles){
if (number.has(headline)){
articlesContainingNumber.push(headline);
break;
}
}

return articlesContainingNumber;

}


/*
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.
The Financial Times wants to understand what the average
number of characters in an article title is.
Implement the function below .
// expect(averageNumberOfCharacters(ARTICLE_TITLES)).toEqual(65);
//to use Math.round(x)
*/
function averageNumberOfCharacters(allArticleTitles) {
// TODO
}
//let averageCharacterNumber = averageNumberOfCharacters / allArticleTitles.length;
let averageCharacterNumber = 0;
for (let Titles of allArticleTitles){
averageCharacterNumber = averageCharacterNumber + Titles.length;
}
let ((averageCharacterNumber + allArticleTitles.length) /Titles);

}
//averageNumber;
//not finished yet******


/* ======= List of Articles - DO NOT MODIFY ===== */
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Like learning a musical instrument, programming requires daily practise.
Like learning a musical instrument, programming requires daily practice.

The exercises are split into three folders: `exercises`, `mandatory` and `extra`. All homework in the `exercise` and `mandatory` section **must** be completed for homework by the following lesson.

Expand All @@ -21,7 +21,7 @@ This is a **private** repository. Please request access from your Teachers, Budd

## Instructions for submission

For your homework, we'll be using [**test driven development**](https://medium.com/@adityaalifnugraha/test-driven-development-tdd-in-a-nutshell-b9e05dfe8adb) to check your answers. Test driven development (or TDD) is the practice of writing tests for your code first, and then write your code to pass those tests. This is a very useful way of writing good quality code and is used in a lot of industries. You don't have to worry about knowing how this works, but if you're curious, engage with a volunteer to find out more! :)
For your homework, we'll be using [**test driven development**](https://medium.com/@adityaalifnugraha/test-driven-development-tdd-in-a-nutshell-b9e05dfe8adb) to check your answers. Test driven development (or TDD) is the practice of writing tests for your code first, and then write your code to pass those tests. This is a very useful way of writing good quality code and is used in a lot of industries. You don't have to worry about knowing how this works, but if you're curious, engage with a volunteer to find out more! :

1. Complete the challenges in each file and save it once you're happy with your changes
2. Run the script to check the results against the tests - all tests should read PASSED if you completed the challenges correctly. If a test reads FAILED, find the associated test to identify which function failed and fix it.
Expand Down