diff --git a/Week2/homework/.vscode/settings.json b/Week2/homework/.vscode/settings.json
new file mode 100644
index 000000000..8d84069c4
--- /dev/null
+++ b/Week2/homework/.vscode/settings.json
@@ -0,0 +1,5 @@
+{
+ "cSpell.words": [
+ "squirtle"
+ ]
+}
\ No newline at end of file
diff --git a/Week2/homework/index.html b/Week2/homework/index.html
new file mode 100644
index 000000000..a92aa53d5
--- /dev/null
+++ b/Week2/homework/index.html
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+ Codestin Search App
+
+
+ Pokemon Sprites
+
+
+
diff --git a/Week2/homework/maartjes-work.js b/Week2/homework/maartjes-work.js
index 49772eb44..d06babc54 100644
--- a/Week2/homework/maartjes-work.js
+++ b/Week2/homework/maartjes-work.js
@@ -45,9 +45,17 @@ const tuesday = [
const maartjesTasks = monday.concat(tuesday);
const maartjesHourlyRate = 20;
+/**
+ * Use of High order functions: map, filter, toFixed
+ */
+
function computeEarnings(tasks, hourlyRate) {
- // Replace this comment and the next line with your code
- console.log(tasks, hourlyRate);
+ // mapping duration of tasks from minutes to hours and filtering out duties < 2h
+ const timeInHours = tasks.map(time => time.duration / 60).filter(duty => duty >= 2);
+ const salaryPerDay = timeInHours.map(hoursPerDay => hoursPerDay * hourlyRate);
+ const totalSalary = salaryPerDay.reduce((sum, dailySalary) => sum + dailySalary, 0);
+ const euroSalary = totalSalary.toFixed(2);
+ return euroSalary;
}
// 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..1e3a5198d 100644
--- a/Week2/homework/map-filter.js
+++ b/Week2/homework/map-filter.js
@@ -1,12 +1,16 @@
'use strict';
-
function doubleOddNumbers(numbers) {
// Replace this comment and the next line with your code
+ // the following iterates the variables in numbers(with filter) and checking if they´re divisible by 2
+ // const newNumbers = [];
+ // for (let i = 0; i =numbers.length)
+ numbers = numbers.filter(num => num % 2 === 1).map(num => num * 2);
console.log(numbers);
+ return numbers;
}
const myNumbers = [1, 2, 3, 4];
-console.log(doubleOddNumbers(myNumbers));
+console.log(doubleOddNumbers(myNumbers)); // output : [2, 6]
// 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..a83760fcf 100644
--- a/Week2/homework/squirtle-sprites.js
+++ b/Week2/homework/squirtle-sprites.js
@@ -7,5 +7,12 @@
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}';
}
+// changing JSOn to JS
+const returnJs = JSON.parse(fetchPokemonData());
+for (const i in returnJs.sprites) {
+ if (returnJs.sprites[i] !== null) {
+ const imageElement = document.createElement('img');
+ imageElement.src = returnJs.sprites[i];
+ document.body.appendChild(pokeImgElement);
/* Code goes below */