From e1c771fb225163e41d1b9a6df17d885907d3436e Mon Sep 17 00:00:00 2001 From: Elena Ackovska Date: Thu, 4 Mar 2021 14:59:43 +0100 Subject: [PATCH 1/6] Added solution for exercises 1 and 2 --- Week2/homework/maartjes-work.js | 12 ++++++++++-- Week2/homework/map-filter.js | 5 +++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Week2/homework/maartjes-work.js b/Week2/homework/maartjes-work.js index 49772eb44..0c1c1e0cc 100644 --- a/Week2/homework/maartjes-work.js +++ b/Week2/homework/maartjes-work.js @@ -46,8 +46,16 @@ const maartjesTasks = monday.concat(tuesday); const maartjesHourlyRate = 20; function computeEarnings(tasks, hourlyRate) { - // Replace this comment and the next line with your code console.log(tasks, hourlyRate); + let earnings = tasks + .map(day => day.duration / 60) + .filter(duration => duration >= 2) + .map(duration => duration * 20) + .reduce((sum, duration) => { + sum += duration; + return sum; + }, 0); + return earnings; } // eslint-disable-next-line no-unused-vars @@ -55,7 +63,7 @@ const earnings = computeEarnings(maartjesTasks, maartjesHourlyRate); // add code to convert `earnings` to a string rounded to two decimals (euro cents) -console.log(`Maartje has earned €${'replace this string with the earnings rounded to euro cents'}`); +console.log(`Maartje has earned €${earnings}`); // Do not change or remove anything below this line module.exports = { diff --git a/Week2/homework/map-filter.js b/Week2/homework/map-filter.js index c8e8a88c1..5c7cb87bd 100644 --- a/Week2/homework/map-filter.js +++ b/Week2/homework/map-filter.js @@ -3,6 +3,11 @@ function doubleOddNumbers(numbers) { // Replace this comment and the next line with your code console.log(numbers); + return numbers + .filter((number) => { + return number % 2 !== 0; + }) + .map((number) => number * 2); } const myNumbers = [1, 2, 3, 4]; From 9e507b307332e682e1713517ce2607ffb98b229d Mon Sep 17 00:00:00 2001 From: Elena Ackovska Date: Thu, 4 Mar 2021 15:24:49 +0100 Subject: [PATCH 2/6] Added solution for exercise 3 - display pokemons --- Week2/homework/index.html | 12 ++++++++++++ Week2/homework/squirtle-sprites.js | 11 +++++++++++ 2 files changed, 23 insertions(+) create mode 100644 Week2/homework/index.html diff --git a/Week2/homework/index.html b/Week2/homework/index.html new file mode 100644 index 000000000..defe7c3c3 --- /dev/null +++ b/Week2/homework/index.html @@ -0,0 +1,12 @@ + + + + + + + Codestin Search App + + + + + diff --git a/Week2/homework/squirtle-sprites.js b/Week2/homework/squirtle-sprites.js index b6b6e2920..9ad4b4462 100644 --- a/Week2/homework/squirtle-sprites.js +++ b/Week2/homework/squirtle-sprites.js @@ -9,3 +9,14 @@ function fetchPokemonData() { } /* Code goes below */ +const data = JSON.parse(fetchPokemonData()); +const imagesUrls = []; +for (key in data.sprites) { + imagesUrls.push(data.sprites[key]); +} + +imagesUrls.forEach(img => { + const image = document.createElement('img'); + image.src = img; + document.querySelector('body').appendChild(image); +}); From cb28c5b4efa6e818ee1f2a9e0621a04bee95a63f Mon Sep 17 00:00:00 2001 From: Elena Ackovska Date: Thu, 4 Mar 2021 15:56:56 +0100 Subject: [PATCH 3/6] Changed let to const --- Week2/homework/maartjes-work.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Week2/homework/maartjes-work.js b/Week2/homework/maartjes-work.js index 0c1c1e0cc..ae0fd1455 100644 --- a/Week2/homework/maartjes-work.js +++ b/Week2/homework/maartjes-work.js @@ -47,7 +47,7 @@ const maartjesHourlyRate = 20; function computeEarnings(tasks, hourlyRate) { console.log(tasks, hourlyRate); - let earnings = tasks + const earnings = tasks .map(day => day.duration / 60) .filter(duration => duration >= 2) .map(duration => duration * 20) From a53b2a274124e1a32bfdfd79891f4ebe7f5614c3 Mon Sep 17 00:00:00 2001 From: Elena Ackovska Date: Thu, 4 Mar 2021 17:41:08 +0100 Subject: [PATCH 4/6] Added toFixed method to round the price in euros --- Week2/homework/index.html | 1 + Week2/homework/maartjes-work.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Week2/homework/index.html b/Week2/homework/index.html index defe7c3c3..69cf8185d 100644 --- a/Week2/homework/index.html +++ b/Week2/homework/index.html @@ -7,6 +7,7 @@ Codestin Search App + diff --git a/Week2/homework/maartjes-work.js b/Week2/homework/maartjes-work.js index ae0fd1455..594f5cf83 100644 --- a/Week2/homework/maartjes-work.js +++ b/Week2/homework/maartjes-work.js @@ -63,7 +63,7 @@ const earnings = computeEarnings(maartjesTasks, maartjesHourlyRate); // add code to convert `earnings` to a string rounded to two decimals (euro cents) -console.log(`Maartje has earned €${earnings}`); +console.log(`Maartje has earned €${earnings.toFixed(2)}`); // Do not change or remove anything below this line module.exports = { From 177ca102fc05786cfe5b759447ef830a6dd1b361 Mon Sep 17 00:00:00 2001 From: Elena Ackovska Date: Thu, 4 Mar 2021 17:59:43 +0100 Subject: [PATCH 5/6] Added filter method and displayImages function on exercise-3 pokemon --- Week2/homework/index.html | 1 + Week2/homework/maartjes-work.js | 4 ++-- Week2/homework/map-filter.js | 8 ++------ Week2/homework/squirtle-sprites.js | 15 ++++++++++----- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/Week2/homework/index.html b/Week2/homework/index.html index 69cf8185d..77fc1e9a5 100644 --- a/Week2/homework/index.html +++ b/Week2/homework/index.html @@ -8,6 +8,7 @@ + diff --git a/Week2/homework/maartjes-work.js b/Week2/homework/maartjes-work.js index 594f5cf83..8efebd444 100644 --- a/Week2/homework/maartjes-work.js +++ b/Week2/homework/maartjes-work.js @@ -46,11 +46,11 @@ const maartjesTasks = monday.concat(tuesday); const maartjesHourlyRate = 20; function computeEarnings(tasks, hourlyRate) { - console.log(tasks, hourlyRate); + // console.log(tasks, hourlyRate); const earnings = tasks .map(day => day.duration / 60) .filter(duration => duration >= 2) - .map(duration => duration * 20) + .map(duration => duration * hourlyRate) .reduce((sum, duration) => { sum += duration; return sum; diff --git a/Week2/homework/map-filter.js b/Week2/homework/map-filter.js index 5c7cb87bd..056ece1ac 100644 --- a/Week2/homework/map-filter.js +++ b/Week2/homework/map-filter.js @@ -2,12 +2,8 @@ function doubleOddNumbers(numbers) { // Replace this comment and the next line with your code - console.log(numbers); - return numbers - .filter((number) => { - return number % 2 !== 0; - }) - .map((number) => number * 2); + // console.log(numbers); + return numbers.filter(number => number % 2 !== 0).map(number => number * 2); } const myNumbers = [1, 2, 3, 4]; diff --git a/Week2/homework/squirtle-sprites.js b/Week2/homework/squirtle-sprites.js index 9ad4b4462..46636a507 100644 --- a/Week2/homework/squirtle-sprites.js +++ b/Week2/homework/squirtle-sprites.js @@ -15,8 +15,13 @@ for (key in data.sprites) { imagesUrls.push(data.sprites[key]); } -imagesUrls.forEach(img => { - const image = document.createElement('img'); - image.src = img; - document.querySelector('body').appendChild(image); -}); +function displayImages() { + imagesUrls + .filter(img => img != null) + .forEach(img => { + const image = document.createElement('img'); + image.src = img; + document.querySelector('body').appendChild(image); + }); +} +displayImages(); From b775c3916b72e8be1a9074976d92e103db3b8e6e Mon Sep 17 00:00:00 2001 From: Elena Ackovska Date: Thu, 4 Mar 2021 18:13:13 +0100 Subject: [PATCH 6/6] Deleted some comments --- Week2/homework/maartjes-work.js | 5 +---- Week2/homework/map-filter.js | 2 -- Week2/homework/squirtle-sprites.js | 5 ----- 3 files changed, 1 insertion(+), 11 deletions(-) diff --git a/Week2/homework/maartjes-work.js b/Week2/homework/maartjes-work.js index 8efebd444..91f4ee7a4 100644 --- a/Week2/homework/maartjes-work.js +++ b/Week2/homework/maartjes-work.js @@ -58,11 +58,8 @@ function computeEarnings(tasks, hourlyRate) { return earnings; } -// eslint-disable-next-line no-unused-vars -const earnings = computeEarnings(maartjesTasks, maartjesHourlyRate); - -// add code to convert `earnings` to a string rounded to two decimals (euro cents) +const earnings = computeEarnings(maartjesTasks, maartjesHourlyRate); console.log(`Maartje has earned €${earnings.toFixed(2)}`); // Do not change or remove anything below this line diff --git a/Week2/homework/map-filter.js b/Week2/homework/map-filter.js index 056ece1ac..bcd16dd4c 100644 --- a/Week2/homework/map-filter.js +++ b/Week2/homework/map-filter.js @@ -1,8 +1,6 @@ 'use strict'; function doubleOddNumbers(numbers) { - // Replace this comment and the next line with your code - // console.log(numbers); return numbers.filter(number => number % 2 !== 0).map(number => number * 2); } diff --git a/Week2/homework/squirtle-sprites.js b/Week2/homework/squirtle-sprites.js index 46636a507..450679269 100644 --- a/Week2/homework/squirtle-sprites.js +++ b/Week2/homework/squirtle-sprites.js @@ -1,9 +1,4 @@ -/* eslint-disable */ -/* - Call this function to get a JSON string of the data - (simulates calling a server to retrieve data) -*/ function fetchPokemonData() { return '{"abilities":[{"ability":{"name":"rain-dish","url":"https://pokeapi.co/api/v2/ability/44/"},"is_hidden":true,"slot":3},{"ability":{"name":"torrent","url":"https://pokeapi.co/api/v2/ability/67/"},"is_hidden":false,"slot":1}],"base_experience":63,"forms":[{"name":"squirtle","url":"https://pokeapi.co/api/v2/pokemon-form/7/"}],"height":5,"held_items":[],"id":7,"is_default":true,"location_area_encounters":"https://pokeapi.co/api/v2/pokemon/7/encounters","name":"squirtle","order":10,"species":{"name":"squirtle","url":"https://pokeapi.co/api/v2/pokemon-species/7/"},"sprites":{"back_default":"https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/back/7.png","back_female":null,"back_shiny":"https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/back/shiny/7.png","back_shiny_female":null,"front_default":"https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/7.png","front_female":null,"front_shiny":"https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/shiny/7.png","front_shiny_female":null},"stats":[{"base_stat":43,"effort":0,"stat":{"name":"speed","url":"https://pokeapi.co/api/v2/stat/6/"}},{"base_stat":64,"effort":0,"stat":{"name":"special-defense","url":"https://pokeapi.co/api/v2/stat/5/"}},{"base_stat":50,"effort":0,"stat":{"name":"special-attack","url":"https://pokeapi.co/api/v2/stat/4/"}},{"base_stat":65,"effort":1,"stat":{"name":"defense","url":"https://pokeapi.co/api/v2/stat/3/"}},{"base_stat":48,"effort":0,"stat":{"name":"attack","url":"https://pokeapi.co/api/v2/stat/2/"}},{"base_stat":44,"effort":0,"stat":{"name":"hp","url":"https://pokeapi.co/api/v2/stat/1/"}}],"types":[{"slot":1,"type":{"name":"water","url":"https://pokeapi.co/api/v2/type/11/"}}],"weight":90}'; }