Problem with lesson 6 return II


#1

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]


#2

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


#3

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
}


#4

difficult to say what caused the problem without seeing what changes you made to the code


#5

console.log(getTotal());


#6

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).


#7

In your getTotal() function you have to pass the orderCount parameter to the getTax() aswell like so:

const getTotal = () => {
   return getSubTotal(orderCount) + getTax(orderCount);
};

When you call getTotal() you need to add parantheses because it’s a function.

console.log(getTotal());

Result:

22.5
23.85

#8

Hello, kameron.kant

Your code needs only two improvements. Line 13 and 20 of your code: getTax and getTotal are missing paretheses:

getTax() inside your getTotal() function
and
console.log(getTotal())

Fix those and your code will work :slight_smile:


#9

Hello, macurious.

getTax() doesn’t have any parameters, so it doesn’t take any arguments. Leave it blank and you’ll get the same result. Cheers :slight_smile:


#10

It turns out there seem to be two different versions of this course.


#11

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. :slightly_frowning_face:


#12

Thanks, got it now. :+1:t3:


#13

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