Pizza returns 0


#1


https://www.codecademy.com/courses/learn-javascript/lessons/functions/exercises/return?action=lesson_resume


The code is giving a subtotal of 0 despite the fact that I've ordered three pizzas and the takeOrder() function is set to increment orderCount.


var orderCount = 0;
var takeOrder = function(topping, crustType) {
  return('Order: ' + crustType + ' crust pizza with ' + topping);
  orderCount++;
};
var getSubTotal = function(itemCount) {
  return (itemCount * 7.5);
};

takeOrder('mushroom', 'thin');
takeOrder('bacon', 'thick');
takeOrder('pepperoni', 'thin');

console.log(getSubTotal(orderCount));


#2

The return statement ends the function immediately, ignoring any code below it. In its current state, your takeOrder() function does not increment orderCount.


#3

OK thanks! By any chance do you know a more technical explanation of why return does that? Is it somehow necessary to avoid some other type of problem?


#4

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