# Having Trouble Getting Formula in Code to Compute Correctly

• 10-23-2013, 03:56 AM
jhern87
Having Trouble Getting Formula in Code to Compute Correctly
Hi everyone, I'm taking an entry level software programming class and am having to write a fairly simple code but can't seem to get it to compute right. This is what my code looks like as of now.

<html>
<body>
Welcome to Cheap Beds, Inc.! Please answer the following questions so we know how much to charge our customers.
<br/>

<script type="text/javascript">

var Origprice;

Origprice = prompt('Enter the Original Price of the bed');

var DelivFee;

DelivFee = prompt ('How much are we charging for delivery?');

var credit;

credit = prompt ('How much are we crediting for their old unit?');

var Newcost;

Newcost = (parseInt(Origprice) + parseInt(DelivFee));

var Finalcost;

Finalcost = (parseInt(Newcost) - parseInt(DelivFee));

alert("The bed that was chosen will cost" + Finalcost + " Including delivery fee and trade-in credit for their old bed");

</script>

</body>
</html>

The cost of the bed that I'm entering is 100, shipping is 20 and credit is 5 but at the end it's saying that the price is 100? Does anyone know how I can fix this?
• 10-23-2013, 04:20 AM
jim829
Re: Having Trouble Getting Formula in Code to Compute Correctly
This is a Java forum, not Javascript.

Regards,
Jim
• 10-23-2013, 10:17 AM
gimbal2
Re: Having Trouble Getting Formula in Code to Compute Correctly
Stackoverflow is a good place to ask for generic programming help.

Needless to say, take a look again at the calculations you are doing because of course the problem is there. Replace the variables you are using with the actual numbers and write out on a piece of paper what the result is going to be. The problem should dawn on you quite quickly that way.