In this chapter I was doing okay until the last part, where it tells me to get the total by calling the function inside a console log statement, but every time I do, I don’t get the total. Here is what I wrote:
var orderCount = 0
function takeOrder(topping, crustType){
console.log('Order: '+ crustType +' pizza topped with '+ topping);
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('ham', 'cheese crust')
takeOrder('pepperoni', 'thin crust')
console.log(getSubtotal(orderCount))
console.log(getTotal)
And here is what I got in the console:
Order: thin crust pizza topped with bacon
Order: cheese crust pizza topped with ham
Order: thin crust pizza topped with pepperoni
22.5
[Function: getTotal]
getTotal is a function, calling a function requires parentheses, here:
console.log(getSubtotal(orderCount))
you call the getSubtotal function correctly, and you use parentheses, yet on the line below, you don’t call the function correctly, one function has a parameter, the other doesn’t, does that confuse you? In both cases, calling the function requires parentheses
Oh, yeah, I forgot about that lol. But still, when I put them, this appears in the console:
Order: thin crust pizza topped with bacon
Order: cheese crust pizza topped with ham
Order: thin crust pizza topped with pepperoni
22.5
22.5function getTax(){
return getSubtotal(orderCount) * 0.06
}
I think I see the problem but I am still learning and don’t really understand why/how it actually works yet.
I have:
const getTax = (orderCount) => {
where you have:
function getTax=() {
So you probably need to add orderCount inside the parentheses. Does that fix it? And if so, do you know why it needs the orderCount parameter there and not in the getTotal function? I think it’s because the orderCount’s returned value has just been updated to equal the price (the sub total, that is) in the previous code block (the getSubTotal function).
Thank you for the clarification! I had this first course where it says it takes the parameter orderCount.
Very confusing! I thought the entire time that i didn’t understand the code.