NW6 | Rabia Avci | JS3 Module | [TECH ED] Programmer Humour | Week 3 #315
NW6 | Rabia Avci | JS3 Module | [TECH ED] Programmer Humour | Week 3 #315RbAvci wants to merge 8 commits intoCodeYourFuture:mainfrom
Conversation
|
| console.log('The names of the people who belong to the Gryffindor house:') | ||
|
|
||
| hogwarts.filter(({house}) => house === "Gryffindor") | ||
| .forEach(({firstName,lastName}) => console.log(`${firstName} ${lastName}`)); | ||
|
|
||
| console.log('The names of teachers who have pets:') | ||
|
|
||
| hogwarts.filter(({pet,occupation})=> pet !== null && occupation === "Teacher" ) | ||
| .forEach(({firstName,lastName}) => console.log(`${firstName} ${lastName}`)); |
| function formatPrice(price) { | ||
| return price.toFixed(2); | ||
| } | ||
|
|
||
| console.log("QTY\tITEM\t\t\tTOTAL"); | ||
|
|
||
| let total = 0; | ||
|
|
||
| for (const {quantity, itemName, unitPrice} of order) { | ||
| console.log(`${quantity}\t${itemName}\t\t${(unitPrice * quantity).toFixed(2)}`); | ||
| total += unitPrice * quantity; | ||
| } | ||
|
|
||
| console.log("\nTotal:", formatPrice(total)); | ||
|
|
There was a problem hiding this comment.
Well done finding a solution!
Also, an improvement you could make to this solution would be to use Array.reduce() to create a running aggregate instead of defining totalPrice outside of the loop.
Here is a link that explains using reduce to calculate a sum.
https://linuxhint.com/call-reduce-on-an-array-of-objects-to-sum-their-properties/
Also, you have used toFixed() on line 19, but then used the formatPrice function on line 23, I would encourage you to be consistent and either use formatPrice in both instances of remove this function and use toFixed(2) on line 23.
| h1 { | ||
| color: aliceblue; | ||
| max-width: 100%; | ||
| padding: 10px; | ||
| background-color: #c24242; | ||
|
|
||
| } | ||
|
|
||
| img { | ||
| max-width: 100%; | ||
| height: auto; | ||
| box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); | ||
| background-color: #c24242; | ||
| padding: 2rem; | ||
|
|
||
| } | ||
|
|
||
| footer { | ||
| color: aliceblue; | ||
| padding: 1px; | ||
| max-width: 100%; | ||
| border: solid 2px #c24242; | ||
| margin-top: 10px; | ||
| background-color: #c24242; | ||
|
|
||
| } No newline at end of file |
There was a problem hiding this comment.
It is not advisable to set CSS values on generic HTML elements such as img, div, h1, h2 etc.
Doing this will mean you will apply these styles to every element you create.
Instead, use classNames on HTML elements to apply styling to specific elements without affecting anything that doesn't have this className.
There was a problem hiding this comment.
Hi Jack, yes that's good advice for me. I thought it was a small project and that it was ok to use like this, I will consider it from now on. Thank you!




Learners, PR Template
Self checklist
Changelist
A basic web application that fetches and displays the latest xkcd comic, including an HTML structure, CSS for styling, and JavaScript for API fetching and rendering.
Questions
Ask any questions you have for your reviewer.