Hey guys I have a question Id like to know what this line of code is referring to in the meal maker project " const totalPrice = appetizer.price + main.price + dessert.price;" I’m not sure how it works is it trying to access the getters for the the appetizers, mains, and desserts ? Im so totally lost any thing helps btw my code doesnt have the line of code in question within it I saw another user posted their code of the same project and took it to use for this question. I really dont wanna cooy and paste code without knowing what it does. Any answers are appreciated.
That expression looks like one that could be used more than once in a program so we would not declare it a constant.
const = Math.PI;
const keyword is for declaring variables that we do not want to change at any time during the session (single values) or data structures that we do not want removed or overwritten.
Data structures such as ojbects and arrays can be declared as constant but still have items added to them, removed from them, and modified by the program. The structures themself are permanent (for the session).
var totalPrice = appetizer.price + main.price + dessert.price;
is how I would write that line. However if the author has not given this any thought beyond a once-through session and expects us to use,
const then we have no choice but to humor them.
The line itself is simply a summation of the three values into a single total that can be polled later in the progrram.