diff --git a/Week2/homework/index.html b/Week2/homework/index.html new file mode 100644 index 000000000..71a8e2aa5 --- /dev/null +++ b/Week2/homework/index.html @@ -0,0 +1,12 @@ + + + + + + + Document + + + + + \ No newline at end of file diff --git a/Week2/homework/maartjes-work.js b/Week2/homework/maartjes-work.js index 49772eb44..98563f5d5 100644 --- a/Week2/homework/maartjes-work.js +++ b/Week2/homework/maartjes-work.js @@ -42,20 +42,22 @@ const tuesday = [ }, ]; -const maartjesTasks = monday.concat(tuesday); +const maartjesTasks = [...monday, ...tuesday]; const maartjesHourlyRate = 20; function computeEarnings(tasks, hourlyRate) { - // Replace this comment and the next line with your code - console.log(tasks, hourlyRate); + return tasks + .map(task => task.duration / 60) + .filter(duration => duration >= 2) + .map(duration => duration * hourlyRate) + .reduce((total, earning) => total + earning, 0); } +console.log(computeEarnings(maartjesTasks, maartjesHourlyRate)); // eslint-disable-next-line no-unused-vars -const earnings = computeEarnings(maartjesTasks, maartjesHourlyRate); - +const earnings = computeEarnings(maartjesTasks, maartjesHourlyRate).toFixed(2); // 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..ef5755c0f 100644 --- a/Week2/homework/map-filter.js +++ b/Week2/homework/map-filter.js @@ -1,9 +1,7 @@ 'use strict'; -function doubleOddNumbers(numbers) { - // Replace this comment and the next line with your code - console.log(numbers); -} +const doubleOddNumbers = numbers => + numbers.filter(number => number % 2 !== 0).map(oddNumber => oddNumber * 2); const myNumbers = [1, 2, 3, 4]; console.log(doubleOddNumbers(myNumbers)); diff --git a/Week2/homework/squirtle-sprites.js b/Week2/homework/squirtle-sprites.js index b6b6e2920..e63c34fc7 100644 --- a/Week2/homework/squirtle-sprites.js +++ b/Week2/homework/squirtle-sprites.js @@ -9,3 +9,34 @@ function fetchPokemonData() { } /* Code goes below */ + +const displaySprites = () => { + const data = JSON.parse(fetchPokemonData()); + const { sprites } = data; + const section = document.createElement('section'); + + for (const key in sprites) { + const div = document.createElement('div'); + const img = document.createElement('img'); + if (sprites[key]) { + img.src = sprites[key]; + section.appendChild(div); + div.appendChild(img); + } + } + // const spritesKeys = Object.keys(sprites); + // console.log(spritesKeys); + // spritesKeys.forEach(key => { + // const div = document.createElement('div'); + // const img = document.createElement('img'); + // if (sprites[key]) { + // img.src = sprites[key]; + // section.appendChild(div); + // div.appendChild(img); + // } + // }); + + document.body.appendChild(section); +}; + +displaySprites();