Having Trouble Getting Formula in Code to Compute Correctly

• 10-22-2013, 09:17 PM
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, 02:17 AM
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));`
• 10-23-2013, 12:55 PM
jhern87
Quote:

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!

X vBulletin 4.2.2 Debug Information

• Page Generation 0.07169 seconds
• Memory Usage 2,351KB
• Queries Executed 11 (?)
Template Usage (21):
• (2)bbcode_code_printable
• (1)bbcode_quote_printable
• (1)footer
• (1)gobutton
• (1)navbar_moderation
• (1)navbar_noticebit
• (2)option
• (1)spacer_close
• (1)spacer_open

Phrase Groups Available (3):
• global
• postbit
Included Files (19):
• ./global.php
• ./includes/class_bootstrap.php
• ./includes/init.php
• ./includes/class_core.php
• ./includes/config.php
• ./includes/functions.php
• ./includes/class_friendly_url.php
• ./includes/class_hook.php
• ./includes/class_bootstrap_framework.php
• ./vb/vb.php
• ./vb/phrase.php
• ./includes/functions_calendar.php
• ./includes/class_bbcode_alt.php
• ./includes/class_bbcode.php
• ./includes/functions_bigthree.php
• ./includes/functions_notice.php

Hooks Called (41):
• init_startup
• init_startup_session_setup_start
• database_pre_fetch_array
• database_post_fetch_array
• init_startup_session_setup_complete
• global_bootstrap_init_start
• global_bootstrap_init_complete
• cache_permissions
• fetch_foruminfo
• global_state_check
• global_bootstrap_complete
• global_start
• style_fetch
• global_setup_complete
• bbcode_fetch_tags
• bbcode_create
• bbcode_parse_start
• bbcode_parse_complete_precache
• bbcode_parse_complete
• cache_templates
• cache_templates_process
• template_register_var
• template_render_output
• fetch_template_start
• fetch_template_complete
• parse_templates