Home > Back-end >  Pizza order - extra cheese
Pizza order - extra cheese

Time:03-02

I'm having problems understanding JavaScript. I have the following assignment. I'm trying to add to the final cost. the Extra Cheese.

var extraCheeseUpcharge = 1.5
var extraCheese = confirm("Would you like extra cheese?")

if (extraCheese == true) {
  pizza.extraCheese =  true;
  extraCheese = extraCheeseUpcharge   pizza.cost;
} else {
   pizza.extraCheese =  false;
  extraCheese = extraCheeseUpcharge - pizza.cost;
  
}

CodePudding user response:

var extraCheeseUpcharge = 1.5
var extraCheese = confirm("Would you like extra cheese?")

if (extraCheese == true) {
  pizza.extraCheese =  true;
  extraCheese = extraCheeseUpcharge   pizza.cost;
} else {
   pizza.extraCheese =  false;
  extraCheese = pizza.cost;
}

If extraCheese is false, the final price here would be equal to pizza.cost and not extraCheeseUpcharge - pizza.cost

  • Related