-
-
Notifications
You must be signed in to change notification settings - Fork 265
Manchester | 26-ITP-May | Abdu Hassen | Sprint 1 | Destructuring #519
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,26 @@ let hogwarts = [ | |
| occupation: "Teacher", | ||
| }, | ||
| ]; | ||
| function houseGryffindor(hogwarts) { | ||
| for (let individualHogwarts of hogwarts) { | ||
|
Contributor
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.
|
||
| if (individualHogwarts.house === "Gryffindor") { | ||
| let { firstName, lastName } = individualHogwarts; | ||
| console.log(`${firstName} ${lastName}`); | ||
| } | ||
| } | ||
| } | ||
| console.log("`````"); | ||
| houseGryffindor(hogwarts); | ||
| console.log("`````"); | ||
|
|
||
| function teacherWithPets(hogwarts) { | ||
| for (let singlePerson of hogwarts) { | ||
| if (singlePerson.occupation === "Teacher" && singlePerson.pet !== null) { | ||
| let { firstName, lastName } = singlePerson; | ||
| console.log(`${firstName} ${lastName}`); | ||
| } | ||
| } | ||
| } | ||
| console.log("`````"); | ||
| teacherWithPets(hogwarts); | ||
| console.log("`````"); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,3 +6,26 @@ let order = [ | |
| { itemName: "Hot Coffee", quantity: 2, unitPricePence: 100 }, | ||
| { itemName: "Hash Brown", quantity: 4, unitPricePence: 40 }, | ||
| ]; | ||
| console.log("QTY".padEnd(5) + "ITEM".padEnd(22) + "TOTAL"); | ||
|
|
||
| let grandTotal = 0; | ||
|
|
||
| function valueProperty(order) { | ||
| for (let singleOrder of order) { | ||
| let { itemName, quantity, unitPricePence } = singleOrder; | ||
|
|
||
| let itemTotal = quantity * unitPricePence; | ||
| grandTotal += itemTotal; | ||
|
|
||
| console.log( | ||
| String(quantity).padEnd(5) + | ||
| itemName.padEnd(22) + | ||
| (itemTotal / 100).toFixed(2) | ||
| ); | ||
| } | ||
|
|
||
| console.log("---------------------------"); | ||
| console.log("Total: " + (grandTotal / 100).toFixed(2)); | ||
| } | ||
|
|
||
| valueProperty(order); | ||
|
Contributor
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. If you call this function multiple times in a row (even with the same argument), you may discover a bug in your code. |
||
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.
This would introduce the variables in the "global" scope (scope outside the function).
We could de-structure the parameters too.