"demo" is the id of an html element where you want the "You Pay: $...." displayed after the calculation.
We wrap prompts with Number() in order to interpret the inputted values correctly, as numbers.
If the merchandise value is >= 20, we only pay .9*(gas price), a 10% discount.
Call calculate() with the onclick event attribute of the button that controls when the prompts are shown:
... for example.
I have this problem:
Write a program that prompts for gasoline spending (g) and merchandise spending (m) as inputs and produces a total cost based on the following discount: 10 percent off gasoline (g) if m>=20, otherwise no discount. Calculate the total amount the customer should pay.
Prompt 1: Please enter gasoline total ($):
Prompt 2: Please enter merchandise total ($):
(The screen should return the total amount due.)
You Pay: $ ……
After testing your code, copy and paste the entire program to the space below.
Can anyone thats good with javascript do this for me and kind of explain?