Why do you need things inside some functions while others you don't?


#1

Just a quick question — any answer would really help, a couple sentences is enough.

Does anyone know why you have to have something in the getSubTotal function but not in the getTax function??

This is the specific code:
const getTax = () => {
return getSubTotal(orderCount) * 0.06;
}
const getTotal = () => {
return getSubTotal(orderCount) + getTax();

Full exercise:
let orderCount = 0;

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

takeOrder(‘mushroom’, ‘thin crust’);
takeOrder(‘spinach’, ‘whole wheat’);
takeOrder(‘pepperoni’, ‘brooklyn style’);

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

console.log(getSubTotal(orderCount));

const getTax = () => {
return getSubTotal(orderCount) * 0.06;
}
const getTotal = () => {
return getSubTotal(orderCount) + getTax();
}
console.log(getTotal())

<do not remove the three backticks above>

#2

I’m taking ‘thing’ to mean, parameter. Functions may have any number of parameters, including none. It depends the purpose of the function and whether it needs data inputs to do its job.


In this lesson the key is to recognize when the program is working with global variables, and when it is working with local ones.

Notice that the variable is a global.


#3

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