/    Sign up×
Community /Pin to ProfileBookmark

instead of adding together, it concatenates?

Many companies normally charge a shipping and handling charge for purchases. Create a Web page that allows a user to enter a purchase price into a text box and includes a JavaScript function that calculates shipping and handling. Add functionality to the script that adds a minimum shipping and handling charge of $1.50 for any purchase that is less than or equal to $25.00. For any orders over $25.00, add 10% to the total purchase price for shipping and handling, but do not include the $1.50 minimum shipping and handling charge. The formula for calculating a percentage is price * percent / 100. For example, the formula for calculating 10% of a $50.00 purchase price is 50 * 10 / 100, which results in a shipping and handling charge of $5.00. After you determine the total cost of the order (purchase plus shipping and handling), display it in an alert dialog box.

[COLOR=”Blue”]this what I could come up with:[/COLOR]

[COLOR=”Red”]<!DOCTYPE>
<html><head>
<title>Project Two</title>
<meta http-equiv=”content-type” content=”text/html; charset=UTF-8″ />

<script type=”text/javascript”>
/*<CDATA[[*/
var salesPrice = window.prompt(“Please Enter Purchase Price?”, “”);
minShipping = salesPrice * 1.50/100;
maxShipping = salesPrice *
10/100;
(salesPrice <= 25)? totalPrice = salesPrice + minShipping
: totalPrice = salesPrice + maxShipping;
alert(totalPrice);
/*]]>*/
</script>
</head>[/COLOR]

Please note that, we’re still in chapter two of the book.. means that we should not use the if statements as its in chapter 3. thanks

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@toicontienJul 14.2012 — The salesPrice variable is a string, and the "+" operator concatenates stings. You want to convert the return value of window.prompt() into a number:

var salesPrice = [B]Number([/B]prompt("Please Enter Purchase Price?", "")[B])[/B];
×

Success!

Help @AhmedScript spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...