orderCount not needed as arguments


#1

Sorry if this has been asked before but I’ve searched and can’t find this question specifically answered.

I found that the code for the pizza.js in exercise 6 works without needing to pass in orderCount as an argument. The functions can just use the variable declared in the code above anyway. So the below works:

let orderCount = 0;

const takeOrder = (topping, crustType) => {
  
  orderCount++;
  
  console.log(`Order: ${crustType} crust pizza topped with ${topping}`);
  
};

const getSubTotal = () => {
  return orderCount * 7.5;
};

const getTax = () => {
  return getSubTotal() * 0.06;
};

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

takeOrder('pepperoni', 'thick');
takeOrder('bla', 'foo');
takeOrder('bar', 'bee');

console.log(getTotal());

I appreciate that this is just a learning exercise about passing arguments to functions, but I’m curious about the difference between doing it this, and the way it’s directed in the exercise. Is one way more efficient than the other? This seems much easier to read and understand I think.


#2

Ok this question has been asnwered here


#3

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