Skip to content

London | 25-ITP-Sep | Maharit Belai | Sprint 1 | Object-destructuring - #603

Open
MaharitB wants to merge 9 commits into
CodeYourFuture:mainfrom
MaharitB:feature/destructuring
Open

MaharitB wants to merge 9 commits into
CodeYourFuture:mainfrom
MaharitB:feature/destructuring

Conversation

@MaharitB

Copy link
Copy Markdown

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Task code

CYF-1112

Changelist

I have completed the task using object destructuring.

Questions

@MaharitB MaharitB added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Nov 23, 2026
@tee4tao tee4tao added Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Nov 26, 2026
];

function gryffindorHouse(hogwart) {
for ({ firstName, lastName, house } of hogwart) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Something is missing in this loop header. Try running the file in strict mode ("use strict"; at the top) or look at what happens to firstName, lastName and house after the loop. Think about how you'd normally declare a loop variable.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thank you for your support it was really helpful! I have amended the code.


function findPet(hogwart) {
for ({ firstName, lastName, pet } of hogwart) {
if (pet === "Phoenix") console.log(firstName, lastName);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Does this check match what the task asked for? Re-read the requirement: which two conditions does a character need to meet? Does the check here work for any teacher with a pet, or only for the one in this specific data set? What would happen if a second teacher had a different pet?

let total = 0;
console.log(`${"QTY"} ${"ITEM"} ${"Total"}`);

for ({ itemName, quantity, unitPricePence } of orders) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

These variables aren't declared with anything. What would happen if this code ran in strict mode or inside an ES module?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You're yet to fix this

@tee4tao tee4tao added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Nov 26, 2026
@MaharitB MaharitB added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Nov 26, 2026
@tee4tao tee4tao added Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Nov 27, 2026
function findPet(hogwart) {
for (const { firstName, lastName, pet, occupation } of hogwart) {
if (pet && occupation === "Teacher")
console.log(`name of a teacher who has pet ${firstName} ${lastName}`);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Compare your output with the expected result in the task. What would the output look like if you ran this code? Does it match line for line?

);
}

console.log(`\nTotal:${total.toFixed(2)}`);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Run the program and look at the number printed after Total:. Compare it with the expected 14.50. What unit is total in, and what unit is toFixed(2) assuming? Also compare the text between Total: and the number with the expected output.

let total = 0;
console.log(`${"QTY"} ${"ITEM"} ${"Total"}`);

for ({ itemName, quantity, unitPricePence } of orders) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You're yet to fix this


function receipt(orders) {
let total = 0;
console.log(`${"QTY"} ${"ITEM"} ${"Total"}`);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

  • Compare your header with the expected one, character by character: capitalisation of the last word, and the number of spaces between columns.
  • Does the ITEM column in the header start at the same position as the item names in your rows? Print it and check by eye.
  • ${"QTY"}, ${"ITEM"} and ${"Total"} are all string literals being interpolated. Interpolation is for inserting values that vary (variables, expressions). What do these three give you over writing the text directly?
    If the goal is to control column widths, is there a method you're already using in the rows that could build the header too?

total += quantity * unitPricePence;

console.log(
`${quantity.toString().padEnd(4)} ${itemName.toString().padEnd(21)}${((quantity * unitPricePence) / 100).toFixed(2)}`

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The header spacing and the row spacing are set in two different ways. If you changed a column width, how many places would you have to update? Can the header and rows share the same widths?

itemName.toString()
itemName is already a string here, so is this call doing anything?

@tee4tao tee4tao added Reviewed Volunteer to add when completing a review with trainee action still to take. and removed Review in progress This review is currently being reviewed. This label will be replaced by "Reviewed" soon. labels Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Reviewed Volunteer to add when completing a review with trainee action still to take.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants