Stuck on functions exercise 5


#1


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


I am not getting a correct order count. it should be 3 orders multiplies by 7.5, but what i get is just 0. I am not really getting what I am doing wrong. The instructions do seem a tad confusing regarding calling the order count function/ Can someone please help?


var orderCount = 0;

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

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

takeOrder("mushrooms", "thin");
takeOrder("bell peppers", "thick");
takeOrder("onions", "stuffed");

console.log(getSubTotal(orderCount));


#2

Delete the var ,it makes orderCount a local variable.
var orderCount = orderCount + 1;

just write,
orderCount = orderCount + 1
here It modifies global variable when you call takeOrder() funtion!

I hope it helps! :slight_smile:


#3

Yes that works! Thanks a lot greentreemee


#4

You're welcome! Keep up the good work! :slight_smile:


#5

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