Return (What am I missing)?


Followed the directions, getting the correct answer but the step does not give me a green box, i'm missing something.

"Did you call the getSubTotal function with passing in the orderCount as a parameter?"

var orderCount = 0;

function takeOrder(topping, crustType) {
  console.log('Order: ' + crustType + ' topped with ' + topping);
  orderCount = orderCount + 1;

takeOrder('Green Peppers', 'Thin Crust');
takeOrder('Bacon', 'Medium Crust');
takeOrder('Sausage', 'Pan Crust');

function getSubTotal(itemCount) {
  return itemCount * 7.5;

console.log(getSubTotal(3, 7.5)); 

Order: Thin Crust topped with Green Peppers
Order: Medium Crust topped with Bacon
Order: Pan Crust topped with Sausage


"Did you call the getSubTotal function with passing in the orderCount as a parameter?"

The getSubTotal is called like:

console.log(getSubTotal(3, 7.5));

Try calling getSubTotal like:


Also, getSubTotal only accepts one parameter.


that worked, awesome, thanks for your help...I'm so close yet so far lol


Hey, why is it getSubTotal(orderCount) and not getSubTotal(itemCount) like the original getSubTotal function above the last console.log? I don't understand the differentiation of itemCount and orderCount. Thanks.


Your question has to do with the variable's scope.

Notice that in this code:

  • itemCount is local to the getSubTotal function

  • itemCount does not have a value outside of getSubTotal

  • itemCount is never given a value outside of the getSubTotal declaration

On the other hand:

  • orderCount is a global variable and has a value throughout all of the code

When you call getSubTotal you want to pass in a value. Since itemCount does not have a valid value (itemCount value is literally undefined), using itemCount here will not help you.

orderCount starts off being 0 and is modified each time takeOrder is called.

Also, notice that any value could be entered as the argument of getSubTotal.
*Numeric values are the only ones that will make it work as expected.

For example,

function getSubTotal(itemCount) {
  return itemCount * 7.5;  

getSubTotal(0); // returns 0
getSubTotal(1); // returns 7.5
getSubTotal(2); // returns 15
getSubTotal(-1); // returns -7.5

Functions: return pizza.js incorrect answer

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