diff --git a/Week2/homework/index.html b/Week2/homework/index.html new file mode 100644 index 000000000..77fc1e9a5 --- /dev/null +++ b/Week2/homework/index.html @@ -0,0 +1,14 @@ + + + + + + + Codestin Search App + + + + + + + diff --git a/Week2/homework/maartjes-work.js b/Week2/homework/maartjes-work.js index 49772eb44..91f4ee7a4 100644 --- a/Week2/homework/maartjes-work.js +++ b/Week2/homework/maartjes-work.js @@ -46,16 +46,21 @@ 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); + // console.log(tasks, hourlyRate); + const earnings = tasks + .map(day => day.duration / 60) + .filter(duration => duration >= 2) + .map(duration => duration * hourlyRate) + .reduce((sum, duration) => { + sum += duration; + return sum; + }, 0); + 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) -console.log(`Maartje has earned €${'replace this string with the earnings rounded to euro cents'}`); +const earnings = computeEarnings(maartjesTasks, maartjesHourlyRate); +console.log(`Maartje has earned €${earnings.toFixed(2)}`); // 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..bcd16dd4c 100644 --- a/Week2/homework/map-filter.js +++ b/Week2/homework/map-filter.js @@ -1,8 +1,7 @@ '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); } const myNumbers = [1, 2, 3, 4]; diff --git a/Week2/homework/squirtle-sprites.js b/Week2/homework/squirtle-sprites.js index b6b6e2920..450679269 100644 --- a/Week2/homework/squirtle-sprites.js +++ b/Week2/homework/squirtle-sprites.js @@ -1,11 +1,22 @@ -/* 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}'; } /* Code goes below */ +const data = JSON.parse(fetchPokemonData()); +const imagesUrls = []; +for (key in data.sprites) { + imagesUrls.push(data.sprites[key]); +} + +function displayImages() { + imagesUrls + .filter(img => img != null) + .forEach(img => { + const image = document.createElement('img'); + image.src = img; + document.querySelector('body').appendChild(image); + }); +} +displayImages();