Thread: Having Trouble Getting Formula in Code to Compute Correctly

1. Member
Join Date
Oct 2013
Posts
1
Rep Power
0

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?

2. Senior Member
Join Date
Jan 2013
Location
Northern Virginia, United States
Posts
5,908
Rep Power
10

Re: Having Trouble Getting Formula in Code to Compute Correctly

This is a Java forum, not Javascript.

Regards,
Jim

3. Just a guy
Join Date
Jun 2013
Location
Netherlands
Posts
5,114
Rep Power
9

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.
Last edited by gimbal2; 10-23-2013 at 09:19 AM.

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•