# Thread: Having Trouble Getting Formula in Code to Compute Correctly

1. Registered User
Join Date
Oct 2013
Posts
8

## 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>
<head></head>
<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. As simple as the fact that you are adding Origprice and DeliveFee and then deducting the DeliveFee again instead of the credit, should be:
Code:
`Finalcost = (parseInt(Newcost) - parseInt(credit));`

3. Registered User
Join Date
Oct 2013
Posts
8
Originally Posted by simplypixie
As simple as the fact that you are adding Origprice and DeliveFee and then deducting the DeliveFee again instead of the credit, should be:
Code:
`Finalcost = (parseInt(Newcost) - parseInt(credit));`
Agh! I had a feeling it was just something I had out of order in the code.

Thank you very much for your help!

#### Thread Information

##### Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

#### Posting Permissions

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