Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Homework week 2 #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Week2/homework/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>squirtle-sprites</title>
</head>
<body>
<script src="maartjes-work.js"></script>
<script src="map-filter.js"></script>
<script src="squirtle-sprites.js"></script>
</body>
</html>
19 changes: 12 additions & 7 deletions Week2/homework/maartjes-work.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
3 changes: 1 addition & 2 deletions Week2/homework/map-filter.js
Original file line number Diff line number Diff line change
@@ -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];
Expand Down
21 changes: 16 additions & 5 deletions Week2/homework/squirtle-sprites.js
Original file line number Diff line number Diff line change
@@ -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();