It doesn’t make sense for getTotal to not take an argument. There is no sensible place for it to get the order count. It also doesn’t make sense for takeOrder to modify a variable outside itself like it does, that isn’t a sensible place to store that information.
What would make sense is to create a new order:
order = new PizzaOrder();
In this way, you create an order and ask it to modify itself, global state is left untouched and you can have multiple orders being created at the same time without interference.
Because the object knows its orders, one won’t need to tell it how many orders there are when asking for the total.
Alternatively one could do something like starting out with an empty array and passing it into a function along with a new order, and get a new array back which you can pass in again to add more orders, or to pass in to a getTotal function. But having an object take care of its own information storage and bundle up its behaviour as methods makes it easier to use
Oh and even if one does have some tiny script sharing global state between functions, there’s nothing saying there can’t be self-contained functions which don’t get involved in that mess.