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

Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Mohammed Mahdi homework week2 #229

Closed
wants to merge 2 commits into from
Closed
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
22 changes: 19 additions & 3 deletions Week2/homework/maartjes-work.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,33 @@ const tuesday = [
const maartjesTasks = monday.concat(tuesday);
const maartjesHourlyRate = 20;

function computeTasksInHours(maartjesTasksX, celling) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably added an X to this variable name because of an ESLint error about shadowing a variable name. While this solved your problem you have now put the onus on the reader of your code to find out what this X means. A better solution would be to name this parameter simply tasks. It also correctly implies that this function can use to compute the task in hours for *any tasks array, not only the one of Maartje.

The parameter celling is misspelling (ceiling) and also incorrect because it implies a maximum value, whereas here we are concerned with a minimum value. So the name threshold is the accurate name to use.

const marrtjeTasksInHours = maartjesTasksX
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I indicated in an earlier comment, the name marrtje has a spelling error. Her name is maartje.

.map(task => task.duration / 60)
.filter(task => task >= celling);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The result of mapping tasks to hours is an array of hours. Therefore you are filtering hours here and a single element of an hours array is an hour:

.filter(hour => hour >= threshold);

return marrtjeTasksInHours;
}

function computeEarnings(tasks, hourlyRate) {
// Replace this comment and the next line with your code
console.log(tasks, hourlyRate);
const Taskhours = computeTasksInHours(tasks, 2);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable, function and parameter names should be in camelCase (start with a lowercase letter). See [Naming conventions)(https://github.com/HackYourFuture/fundamentals/blob/master/fundamentals/naming_conventions.md).

let rate = 0;
for (const task of Taskhours) {
const Total = task * hourlyRate;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Total -> total

rate += Total;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're concerned here with practicing array methods, why don't you try a .reduce() (preferred) or .forEach() here?

return rate;
// eslint-disable-next-line no-unused-vars
}

// eslint-disable-next-line no-unused-vars
const earnings = computeEarnings(maartjesTasks, maartjesHourlyRate);
const result = earnings.toFixed(2);

// Math.round(rate * 100) / 100;

// 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 €' + result + '.');

// Do not change or remove anything below this line
module.exports = {
Expand Down
5 changes: 3 additions & 2 deletions Week2/homework/map-filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

function doubleOddNumbers(numbers) {
// Replace this comment and the next line with your code
console.log(numbers);
const newNumber = numbers.filter(number => (number % 2 === 1 ? number : false)).map(x => x + x);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The anonymous (arrow) function that you pass as an argument to the filter method should return a boolean (i.e. true or false. In your case you are return false or the number itself. It still works because zero is 'falsy' and non-zero is 'truthy', but that is just sheer luck. Can you fix this by letting the function return a genuine boolean at all times?

return newNumber;
}

const myNumbers = [1, 2, 3, 4];
console.log(doubleOddNumbers(myNumbers));
console.log('Using the filter method :' + doubleOddNumbers(myNumbers));

// Do not change or remove anything below this line
module.exports = {
Expand Down