diff --git a/Week2/homework/index.html b/Week2/homework/index.html
new file mode 100644
index 000000000..305ad20b7
--- /dev/null
+++ b/Week2/homework/index.html
@@ -0,0 +1,12 @@
+
+
+
+
+
+ Document
+
+
+
+
+
+
diff --git a/Week2/homework/maartjes-work.js b/Week2/homework/maartjes-work.js
index 49772eb44..a5714454e 100644
--- a/Week2/homework/maartjes-work.js
+++ b/Week2/homework/maartjes-work.js
@@ -46,8 +46,30 @@ 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);
+ //Map the tasks to durations in hours.
+ const tasksDurationInHours = tasks.map(task => {
+ return {
+ name: task.name,
+ duration: task.duration / 60,
+ };
+ });
+
+
+ //Filter out everything that took less than two hours (i.e., remove from the collection)
+ const filteredTask = tasksDurationInHours.filter(task => {
+ if (task.duration < 2) {
+ return false;
+ } else {
+ return true;
+ }
+ });
+
+ //Multiply the each duration by a per-hour rate for billing (use €20/hour) and sum it all up.
+ const priceArray = filteredTask.map(task => task.duration * 20);
+
+ const totalPrice = priceArray.reduce((a, b) => a + b, 0);
+
+ return Math.round(totalPrice * 100) / 100;
}
// eslint-disable-next-line no-unused-vars
@@ -55,7 +77,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 = {
@@ -63,3 +85,4 @@ module.exports = {
maartjesHourlyRate,
computeEarnings,
};
+
diff --git a/Week2/homework/map-filter.js b/Week2/homework/map-filter.js
index c8e8a88c1..8aad82847 100644
--- a/Week2/homework/map-filter.js
+++ b/Week2/homework/map-filter.js
@@ -1,12 +1,22 @@
'use strict';
-function doubleOddNumbers(numbers) {
- // Replace this comment and the next line with your code
- console.log(numbers);
-}
+function throwAway(numbers) {
+ return numbers.filter(number => {
+ if (number % 2 === 0) {
+ return false;
+ }
+ return number;
+ });
+}
const myNumbers = [1, 2, 3, 4];
-console.log(doubleOddNumbers(myNumbers));
+console.log(throwAway(myNumbers));
+
+function doubleOddNumbers(numbers) {
+ return numbers.map(number => number * 2);
+}
+const newNumbers = throwAway(myNumbers);
+console.log(doubleOddNumbers(newNumbers));
// Do not change or remove anything below this line
module.exports = {
diff --git a/Week2/homework/squirtle-sprites.js b/Week2/homework/squirtle-sprites.js
index b6b6e2920..394b59624 100644
--- a/Week2/homework/squirtle-sprites.js
+++ b/Week2/homework/squirtle-sprites.js
@@ -8,4 +8,40 @@ 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 */
+fetchPokemonData();
+const json = fetchPokemonData();
+const newString = JSON.parse(json);
+
+console.log(newString);
+
+function onlyTheLinks(sprites) {
+ const values = Object.values(sprites);
+ return values.filter(link => {
+ if (link === null) {
+ return false;
+ }
+
+ return true;
+ });
+}
+const links = onlyTheLinks(newString.sprites);
+console.log(links);
+
+/**
+ * [
+ 'https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/back/7.png',
+ 'https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/back/shiny/7.png',
+ 'https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/7.png',
+ 'https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/shiny/7.png'
+]
+ */
+links.map(link => {
+ console.log(link);
+ // create img element
+ let img = document.createElement('img');
+ // set src attribute using link
+ img.setAttribute('src', link);
+ // append to html body
+ document.getElementById('sprites').appendChild(img);
+});
+