-
-
Notifications
You must be signed in to change notification settings - Fork 276
London | 26-ITP-Sep | Mandip Sanger| Sprint 1 | Object destructuring #583
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,3 +70,25 @@ let hogwarts = [ | |
| occupation: "Teacher", | ||
| }, | ||
| ]; | ||
| //## Task 1 | ||
|
|
||
| //- In `exercise.js` write a program that will take the `hogwarts` array as input and display the names of the people who belong to the Gryffindor house. | ||
| //- Use object destructuring to extract the values you need out of each element in the array. | ||
|
|
||
| // Task 1 | ||
| for (const { firstName, house } of hogwarts) { | ||
| if (house === "Gryffindor") { | ||
| console.log(firstName); | ||
| } | ||
| } | ||
|
|
||
| // Task 2 | ||
| for (const { firstName, occupation, pet } of hogwarts) { | ||
| if (occupation === "Teacher" && pet) { | ||
| console.log(firstName); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question as above. |
||
| } | ||
| } | ||
| //## Task 2 | ||
|
|
||
| //- In `exercise.js` write a program that will take the `hogwarts` array as input and display the names of teachers who have pets. | ||
| //- Use object destructuring to extract the values you need out of each element in the array. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,3 +6,16 @@ let order = [ | |
| { itemName: "Hot Coffee", quantity: 2, unitPricePence: 100 }, | ||
| { itemName: "Hash Brown", quantity: 4, unitPricePence: 40 }, | ||
| ]; | ||
| let totalCost = 0; | ||
|
|
||
| for (const { itemName, quantity, unitPricePence } of order) { | ||
| const itemTotal = quantity * unitPricePence; | ||
|
|
||
| console.log( | ||
| `${quantity} ${itemName.padEnd(20)}${(itemTotal / 100).toFixed(2)}` | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you think this can be made more robust in terms of formatting structure? |
||
| ); | ||
|
|
||
| totalCost += itemTotal; | ||
| } | ||
|
|
||
| console.log(`Total: ${(totalCost / 100).toFixed(2)}`); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you manage to compare the output with the one described in readme.md?