If it is supposed to be a web page, then why are you using prompt()
instead of and HTML <form> and form fields? No real web page would ever use prompt()
as you are doing.
Anyway there are several things in your code that don't make sense.
First of all, you keep asking the user for a product inside that loop.
But you store *ALL* the answers into the *ONE* variable named product.
So the second time through the loop, you erase the answer you got in the first time through the loop.
And so on.
When the loop is finally finished the ONLY product you will have is the LAST one the user entered.
Also inside the loop, you keep doing
total = total + price
. But price is zero when you start the loop and is NEVER CHANGED inside the loop, so you will just keep adding zero to the total.
Then you have all this code:
if (product === "ice cream cone")
price = 3 - discount;
discount = (.01 * price);
But discount is set to zero at the top of your code and is not changed before you get to this code. So you are, really, doing
What's the point?
Try this: Pretend YOU are the computer. Or maybe pretend you are in-person asking the customer those questions.
What steps would YOU take and WHEN would you take them, in order to get a correct answer?
WRITE DOWN the steps you would use.
Then get some friend to play the game with you: You ask the questions, you do EXACTLY what your written down steps tell you to do. Does it make sense? Do you get the right answer at the end?
If not, edit those WRITTEN steps and try again, until it works.
*NOW* convert those steps to a program.