Question

Write a javascript program that prompts for the price and the tax rate for shopping in...

Write a javascript program that prompts for the price and the tax rate for shopping in a store. Calculate and display the tax amount and total price. For example, if the user enters 100 for the price and 7% as the tax rate, the program should displays $107.00 as the total price and $7.00 as the tax amount.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Java script program to the given case. Copy the below code and paste it in any text editor and then save it as Cal.html format and then open that file in any browser(google chrome for instance) to run the program.

<html>

<body>

<script type="text/javascript">

//function to calculate and display values

function CalculateAndDisp()

{

//parseing the entered values and assinging them to respective variables

var price = parseFloat(document.getElementById("price").value)

var taxRate =parseFloat(document.getElementById("tax").value)

//checking whether the two numbers are valid or not

if(isNaN(price) || (isNaN(taxRate)))

{

//checking whether the 1st number is valid or not

if (isNaN(price))

{

alert("Please 1st a Number");

}else if(isNaN(taxRate)) //checking whether the 2nd number is valid or not

{

alert("Please 2nd Number");

}

}else //if both two numbers are valid then procede to calculate

{

//addition of price and taxRate

var totalPrice= price+taxRate;

//displaying the total price and tax rate

document.write("Total Price: $"+totalPrice);

//for new line

document.write("<br>");

document.write("Tax Amount: $"+taxRate);

}

}

</script>

<form >

Enter the price: <input type="number" id="price" name="number" /><br /><br />

Enter the tax rate: <input type="number" id="tax" name="number" /><br />

<input type="submit" value="Calculate" onclick="CalculateAndDisp();"/>

</form>

</body>

</html>

Output:

Input page:

Enter the price: 100 Enter the tax rate: 7 Calculate

Output page:

Total Price: $107 Tax Amount:$7

Add a comment
Know the answer?
Add Answer to:
Write a javascript program that prompts for the price and the tax rate for shopping in...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Q1 (2 pts) Shopping list Write a program that prompts a user for items on their...

    Q1 (2 pts) Shopping list Write a program that prompts a user for items on their shopping list and keeps prompting the user until they enter "Done" (make sure your program can stop even if the user enters "Done" with different cases, like "done"), then prints out the items in the list, line by line, and prints the total number of items on the shopping list. Output (after collecting items in the while loop) should look something like this: Apple...

  • In ruby Write a program that prompts the user to enter a year and first day...

    In ruby Write a program that prompts the user to enter a year and first day of the year, and displays the calendar table of that year. For example, if the user entered the year 2019, and 2 for Tuesday, January 1, 2019, your program should display the calendar for each month in the year 2019.

  • C++ Problem #1 Write a program that prompts user to enter an integer up to 1000...

    C++ Problem #1 Write a program that prompts user to enter an integer up to 1000 and displays back a message about the number of digits in this number and if number is odd or even. For example, if user enters 93 message back should be "93 has 2 digits and is odd".

  • Program Requirements ·         The program prompts the user to enter a loan amount and an interest rate....

    Program Requirements ·         The program prompts the user to enter a loan amount and an interest rate. ·         The application calculates the interest amount and formats the loan amount, interest rate, and interest amount. Then, it displays the formatted results to the user. ·         The application prompts the user to continue. ·         The program stops prompting the user for values after taking 3 loan amounts. ·         The application calculates and displays the total loan and interest amount and ends the program Example Output Welcome to...

  • I need to Write a test program that prompts the user to enter 10 double values...

    I need to Write a test program that prompts the user to enter 10 double values into an array, calls a method to calculate the average of the numbers, and displays the average. Next, write a method that returns the lowest value in the array and display the lowest number. The program should then prompt the user to enter 10 integer values into an array, calculates the average, and displays the average. The program should have two overloaded methods to...

  • write a c++ program. A real estate broker sets fees for selling properties according to the...

    write a c++ program. A real estate broker sets fees for selling properties according to the property type as shown in the table. The broker wants you to write a program that prompts the user for the broker type, sale price of the property and the property code. If the user enters an invalid property code or broker code, the program should display an appropriate message and end the program. Allow the user to enter uppercase and lowercase letters. If...

  • Answer using C++ Write a program that will calculate the final sales price of a motorcycle;...

    Answer using C++ Write a program that will calculate the final sales price of a motorcycle; this includes additional optional packages along with sales tax. You may assume that the base? price of the motorcycle is $30,000. First you must ask the user to choose which optional packages they want. The user is only permitted to choose one package. Your program should display a menu of the available packages. The user should enter the package by entering the letter associated...

  • Structures in C++ :- 2. Write a program that declares a structure to store the distance...

    Structures in C++ :- 2. Write a program that declares a structure to store the distance covered by player along with the time taken to cover the distance. The program should input the records of two players and then display the record of the winner. 3. Write a program that declares a structure to store income, tax rate and tax of a person. The program defines an array of structure to store the records of five person. It inputs income...

  • Write a program that prompts the user for a String value and a character value. The...

    Write a program that prompts the user for a String value and a character value. The program should then find the last occurrence of the provided character in the provided String and display the corresponding index. If the character is not found in the String, display -1. For additional challenge, create a multi-class solution. The business class should consist of two instance varaibles to store the user provided values and one method to accomplish the given task. The tester class...

  • JAVA 2. (8 points) Write a code segment which prompts the user to enter the price...

    JAVA 2. (8 points) Write a code segment which prompts the user to enter the price of a tour and receives input from the user. A valid tour price is between $52.95 and $259.95, inclusive. Your program should continue to repeat until a valid tour price has been entered. If the user enters an invalid price, display a message describing why the input is invalid. You may assume that the user only enters a real number. The user will not...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT