Topics discussed this week:
• Functions + JSON/Arrays
• Array Manipulations
• JSON
• Map and filter
• Arrow functions
Here you find the readings you have to complete before the third lecture.
Deadline Monday
Go through the html-css
, javascript1
and javascript2
Github repositories of one of your fellow students, check if they have neat repository's with the different weeks (eg. week1
, week2
, week3
)of homework for all the modules up and until now. Also check if they have hosted their homework on Github pages. If there is anything that they can improve please provide feedback in an issue.
Deadline Wednesday
2.1 Say you would like to write a program that doubles the odd numbers in an array and throws away the even number.
Your solution could be something like this:
const numbers = [1, 2, 3, 4];
const newNumbers = [];
for (let i = 0; i < numbers.length; i++) {
if (numbers[i] % 2 !== 0) {
newNumbers.push(numbers[i] * 2);
}
}
console.log('The doubled numbers are', newNumbers); // ==> [2, 6]
Rewrite the above program using map
and filter
don't forget to use =>
.
2.2 Underneath you see a very interesting small insight in Maartje's work:
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 tasks = monday.concat(tuesday);
Note: the durations are specified in minutes.
Write a program that computes how much Maartje has earned by completing these tasks, using map
and filter
. For the 'summing part' you can try your luck with reduce
; alternatively, you may use forEach
or a for
loop.
Follow these steps. Each step should build on the result of the previous step.
- Map the tasks to durations in hours.
- Filter out everything that took less than two hours (i.e., remove from the collection)
- Multiply the each duration by a per-hour rate for billing (you can decide yourself what Maartje should earn per hour) and sum it all up.
- Output a formatted Euro amount, rounded to Euro cents, e.g:
€ 12.34
. - Choose variable and parameters names that most accurately describe their contents or purpose. When naming an array, use a plural form, e.g.
durations
. For a single item, use a singular form, e.g.duration
. For details, see Naming Conventions. - Don't forget to use
=>
.
Finish up to chapter 7: JSON on roverjs.com! (Alternative site: roverjs.taalmap.nl)
Deadline Saturday
Deadline Sunday morning
Go trough the reading material in the README.md to prepare for your next class
Go over your homework one last time:
- Does every file run without errors and with the correct results when you run them with Node?
- Does every file start with
'use strict';
? - Have you used
const
andlet
and avoidedvar
? - Do the variable, function and argument names you created follow the Naming Conventions?
- Is your code well-formatted (see Code Formatting)?
- Have you resolved all issues flagged by ESLint and the spell checker (no wavy red and green underlines in VSCode)?
If the answer is 'yes' to all preceding questions you are ready to follow these instructions: