Pizza JavaScript Exercise


#1

var orderCount = 0;

function takeOrder(topping, crustType) {
console.log("Order pizza with " + topping + " and " + crustType);
orderCount = orderCount + 1;
}

function getSubTotal(itemCount) {
return itemCount * 7.5;
}

function getTax() {
return getSubTotal(orderCount) * 0.06;
}

function getTotal() {
return getSubTotal(orderCount) + getTax();
}

takeOrder(“bacon”, “thin crust”);
takeOrder(“meatlovers”, “thick crust”);
takeOrder(“hawaiian”, “no crust”);

console.log(getSubTotal(orderCount));
console.log(getTotal());

/*
This is my code, i’m not exactly sure what the “itemCount” is supposed to do (the instructions say to put it there, but I think it’s a mistake and should be orderCount instead)

Can someone please clarify this? If the itemCount thing is indeed correct, what does it actually do in the code? the values don’t change if I change itemCount to orderCount, why is that?

thx very much!!
*/


#2

Variable names are just identifiers, their naming does not affect execution:

let a = 2;
console.log(a * 2);  // 4

let b = 2;
console.log(b * 2);  // 4

What matters is what you do with the values, that you for example don’t mix them up somehow

console.log(c * 2);  // 3124890734789 ?? where did c come from

#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.