From cdd5f45e69c47a55962574ea16e96cfe755b3bbf Mon Sep 17 00:00:00 2001 From: Maen Date: Wed, 16 Jan 2019 22:12:18 +0100 Subject: [PATCH] Homework JavaScript2 week2 --- Week2/homework/maartjes-work.js | 104 +++++++++++++++++--------------- Week2/homework/map-filter.js | 21 ++++--- 2 files changed, 66 insertions(+), 59 deletions(-) diff --git a/Week2/homework/maartjes-work.js b/Week2/homework/maartjes-work.js index fc8c0e633..e6bb95c3e 100644 --- a/Week2/homework/maartjes-work.js +++ b/Week2/homework/maartjes-work.js @@ -1,65 +1,69 @@ 'use strict'; -const monday = [ - { - name: 'Write a summary HTML/CSS', - duration: 180 - }, - { - name: 'Some web development', - duration: 120 - }, - { - name: 'Fix homework for class10', - duration: 20 - }, - { - name: 'Talk to a lot of people', - duration: 200 - } +const monday = [{ + name: 'Write a summary HTML/CSS', + duration: 180 + }, + { + name: 'Some web development', + duration: 120 + }, + { + name: 'Fix homework for class10', + duration: 20 + }, + { + name: 'Talk to a lot of people', + duration: 200 + } ]; -const tuesday = [ - { - name: 'Keep writing summary', - duration: 240 - }, - { - name: 'Some more web development', - duration: 180 - }, - { - name: 'Staring out the window', - duration: 10 - }, - { - name: 'Talk to a lot of people', - duration: 200 - }, - { - name: 'Look at application assignments new students', - duration: 40 - } +const tuesday = [{ + name: 'Keep writing summary', + duration: 240 + }, + { + name: 'Some more web development', + duration: 180 + }, + { + name: 'Staring out the window', + duration: 10 + }, + { + name: 'Talk to a lot of people', + duration: 200 + }, + { + name: 'Look at application assignments new students', + duration: 40 + } ]; 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); -} +const durationInHours = maartjesTasks.map(inHours => inHours.duration / 60); +console.log(durationInHours); -// eslint-disable-next-line no-unused-vars -const earnings = computeEarnings(maartjesTasks, maartjesHourlyRate); +const moreThanTweHours = durationInHours.filter(tweHours => tweHours >= 2); +console.log(moreThanTweHours); -// add code to convert `earnings` to a string rounded to two decimals (euro cents) +const computeEarnings = moreThanTweHours + .map(manyPerHours => manyPerHours * maartjesHourlyRate) + .reduce((total, manyPerHours) => total + manyPerHours, 0); +console.log(computeEarnings); + + +const currencyFormatter = new Intl.NumberFormat('NL', { style: 'currency', currency: 'EUR' }); + +const formattedCosts = currencyFormatter.format(computeEarnings); +console.log("Maartje has earned " + formattedCosts); -console.log(`Maartje has earned €${'replace this string with the earnings rounded to euro cents'}`); // Do not change or remove anything below this line module.exports = { - maartjesTasks, - maartjesHourlyRate, - computeEarnings -}; + maartjesTasks, + maartjesHourlyRate, + computeEarnings +}; \ No newline at end of file diff --git a/Week2/homework/map-filter.js b/Week2/homework/map-filter.js index ab3c622d4..d27708df8 100644 --- a/Week2/homework/map-filter.js +++ b/Week2/homework/map-filter.js @@ -1,15 +1,18 @@ 'use strict'; -function doubleOddNumbers(numbers) { - // Replace this comment and the next line with your code - console.log(numbers); -} - const myNumbers = [1, 2, 3, 4]; -console.log(doubleOddNumbers(myNumbers)); + +const doubleOddNumbers = myNumbers + .filter(odd => odd % 2 !== 0) + .map(odd => odd * 2); + +console.log(doubleOddNumbers); + + + // Do not change or remove anything below this line module.exports = { - myNumbers, - doubleOddNumbers -}; + myNumbers, + doubleOddNumbers +}; \ No newline at end of file