I'm really new to programming, so please excuse the inexperience. I've been playing around with JavaScript and I wrote this little tip calculator program:
var service = window.prompt("Was your service great, good, average, or bad?");
if (service = 'great'){
let total = bill * (1.2)
console.log(total)
};
if (service = 'good'){
let total = bill * (1.1)
console.log(total)
};
if (service = 'average'){
let total = bill * (1.05)
console.log(total)
};
if (service = 'bad'){
console.log("Write a scathing online review! No tip!")};
I got it to kind of work a little while ago, but there's a glaring bug. Instead of checking to see which if statement is true and executing only that code, the program just executes all the code within all the statements regardless of user input.
How can I fix this?
Aucun commentaire:
Enregistrer un commentaire