Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8219845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:19:04+00:00 2026-06-07T13:19:04+00:00

Possible Duplicate: In JavaScript doing a simple shipping and handling calculation Many companies normally

  • 0

Possible Duplicate:
In JavaScript doing a simple shipping and handling calculation

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.

<!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>

I please need to have all my script checked and note that, we’re still in chapter 2 thus (if) statements are not allowed to be used yet.
Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T13:19:06+00:00Added an answer on June 7, 2026 at 1:19 pm

    First of all, your ternary operator seems to be quite repetetive. There is a way to make it shorter:

    totalPrice = salesPrice + ( salesPrice <= 25 ? minShipping : maxShipping );
    

    Then, it is a good habit to declare your variables before you use them using var keyword. In this particular case the advice is useless, since the script will be executed in the global scope, so all your variables will end up being global.

    Your version of script concatenates the result since the return type of window.prompt is String. And when the one tries to add a String to a Number, the latter just gets converted into a String and the concatenation occurs.

    You can explicitly convert String to Number by using built-in parseInt (or parseFloat) functions or by adding a plus sign.

    <script type="text/javascript">
    /*<CDATA[[*/
    var salesPrice, minShipping, maxShipping, totalPrice;
    
    salesPrice  = +window.prompt( 'Please Enter Purchase Price?', '' ),
    minShipping = salesPrice * 1.5 / 100;
    maxShipping = salesPrice * 10  / 100;
    
    totalPrice  = salesPrice + ( salesPrice <= 25 ? minShipping : maxShipping );
    
    alert( totalPrice );
    /*]]>*/
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: gwt and javascript files Seems like a simple enough task, but i'm
Possible Duplicate: Convert string to Pascal Case (aka UpperCamelCase) in Javascript I'm doing some
Possible Duplicate: Javascript closure inside loops - simple practical example How can I make
Possible Duplicate: How to enable PHP short tags? I am doing some JavaScript work
Possible Duplicate: Javascript create variable from its name The code below checks to see
Possible Duplicate: Javascript closure inside loops - simple practical example Rather than explaining the
Possible Duplicate: JavaScript: why does parseInt(1/0, 19) return 18? Why does parseInt(1/0, 19) evaluate
Possible Duplicate: JavaScript Variable inside string without concatenation - like PHP In PHP, double
Possible Duplicate: Javascript force open a link in a browser I am working on
Possible Duplicate: JavaScript: var functionName = function() {} vs function functionName() {} AFAIK, there

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.