Total cost shows up as $0 in my js restaurant demo. Why?
mhs_mhs123 (4)

Hey everyone, I am a new python and js dev and I'm trying to learn the syntax for both these languages. I'm currently working on a restaurant demo in javascript. Everything works great until the last alert message where it displays the total cost as $0 for the user. Any help would be appreciated. Thanks and have a great day!

You are viewing a single comment. View All
Answered by eankeen (796) [earned 5 cycles]
View Answer
eankeen (796)

Yah so at the beginning of your program, you have

var costmeal = 0;
var costdrink = 0;
var totalcost = Number((costmeal + costdrink));

So since costmeal and costdrink are both 0, totalcost is going to be zero. Later in the program, it doesn't seem like you add anything to totalcost, which is why it shows at $0. Right before each if statement, you might want to add costmeal or costdrink to totalcost.

Hope I was able to help =P

eankeen (796)

@mhs_mhs123 Yeah, but when you change constmeal, it doesn't automatically update totalcost, unfortunately.

So you might have to do something like this

var totalcost = Number((costmeal + costdrink));

near the end of your program, rather than the beginning (because at the beginning costmeal and costdrink are 0) :)

mhs_mhs123 (4)

@eankeen Thanks for your advice. I'll try it and let you know

mhs_mhs123 (4)

@eankeen a quick q. I declare costmeal to have a cost. for example in line 13:

costmeal = Number(amtofslices)*3;

Doesn't this count?