orderCount not needed as arguments

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) => {
  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');


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.

Ok this question has been asnwered here

1 Like

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