Scope, variables, functions


#1


https://www.codecademy.com/en/courses/learn-javascript/lessons/functions/exercises/return

I don't have any error messages I'm just confused about the concepts presented here and how they might contradict or be an exception to global and functional scope.

My question is why do we have to use orderCount as a parameter in the getTax and getTotal functions. Why did we need itemCount at all? How are we alble to use it if we modified orderCount in the takeOrder function...shouldn't that now be functional scope?..or is it still global because it's also outside?


var orderCount=0;


function takeOrder(topping, crustType){
  orderCount= orderCount+1;
  console.log('Order:' + crustType +' crust pizza topped with' + topping );
}
takeOrder(" bacon", "thin");
takeOrder(' red pepper', 'garlic and herb');
takeOrder(' sausage', 'stuffed');
takeOrder('mushroom', 'ceasar');

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

function getTax(){
return getSubTotal(orderCount)* 0.06;
}
console.log( getSubTotal(orderCount));

function getTotal(){
  return getSubTotal(orderCount) + getTax();
}

console.log(getTotal());


#2

Two discussion threads might help you!

and

I hope it helps you! :slight_smile:


#3

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