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 3624326
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:29:38+00:00 2026-05-18T23:29:38+00:00

I am having trouble with a simple JavaScript calculation. My document is supposed to

  • 0

I am having trouble with a simple JavaScript calculation. My document is supposed to add $1.50 to an order if it is $25 or less, or add 10% of the order if it is more then $25. The exact problem is:

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.

This is my code:

    var price = window.prompt("What is the purchase price?", 0);
var shipping = calculateShipping(price);
var total = price + shipping;
function calculateShipping(price){
if (price <= 25){
 return 1.5;
}
else{
 return price * 10 / 100
}
}
window.alert("Your total is $" + total + ".");

When testing I enter a number in the prompt box, and instead of calculating as if I entered a number it calculates as if I entered a string. i.e. i enter 19 and it gives me 191.5 or I enter 26 and it gives me 262.6

  • 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-05-18T23:29:38+00:00Added an answer on May 18, 2026 at 11:29 pm

    Using parseFloat will help you:

    var price = parseFloat(window.prompt("What is the purchase price?", 0))
    var shipping = parseFloat(calculateShipping(price));
    var total = price +shipping;
    function calculateShipping(price){
    if (price <= 25){
     return 1.5;
    }
    else{
     return price * 10 / 100
    }
    }
    window.alert("Your total is $" + total + ".");
    

    See it working at: http://jsfiddle.net/e8U6W/

    Also, a little-known put more performant way of doing this would be simply to -0:

    var price =window.prompt("What is the purchase price?", 0) - 0;
    

    (See: Is Subtracting Zero some sort of JavaScript performance trick?)

    Be sure to comment this, though as its not as obvious to those reading your code as parseFloat

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble figuring out how to do a simple Javascript task on fields
I'm having trouble with a simple radio set of two radio buttons (I don't
I'm new to linq and having trouble writing two simple queries. For some reason,
I'm having trouble sending out a simple HTTP request using Actionscript 3's Socket() object.
I'm having trouble with what should be a simple program. I've written a single
I am having trouble drawing a line within a group box in a simple
I am having trouble working out how to get a simple fade in fade
I'm having trouble with Poco libraries. I need a simple solution to make the
My program generates relatively simple PDF documents on request, but I'm having trouble with
I'm building a simple web-based RSS reader in Python, but I'm having trouble parsing

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.