Question

In: Computer Science

Javascript Calculator Algorithm to calculate a tip percentage given the bill amount and total bill including...

Javascript Calculator

Algorithm to calculate a tip percentage given the bill amount and total bill including tip.

Asker suer for bill without tip:

Ask the user for total bill with tip:

Ask the user how many people splitting bill:

Submit button to calculate the tip percentage

Solutions

Expert Solution

HTML & Javascript:

<!DOCTYPE html>
<html>
  
   <head>
       <script type="text/javascript">
          
           //Function that calculates tip percentage
           function calculateTipPercentage() {
               //Reading input from user
               var billWithoutTip = parseFloat(document.getElementById("W_O_Tip").value);  
               var billWithTip = parseFloat(document.getElementById("W_Tip").value);
               var numPeople = parseFloat(document.getElementById("numP").value);
              
               //Calculating tip amount
               var tipAmt = billWithTip - billWithoutTip;
              
               //Calculating tip percentage
               var tipPercentage = (billWithTip - billWithoutTip) / 100;
              
               //Writing result
               document.getElementById("Tip_Per").value = tipPercentage + "%";
           }
          
       </script>
   </head>
  
   <body>
       Enter total bill without tip: <input type="text" id="W_O_Tip"> </br></br>
       Enter total bill with tip: <input type="text" id="W_Tip"> </br></br>
       Enter number of people splitting the bill: <input type="text" id="numP"> </br></br>
       <input type="submit" value="Submit" onclick="calculateTipPercentage()"> </br></br>
       Tip Percentage: <input type="text" id="Tip_Per" readonly=true> </br></br>
   </body>
  
</html>

__________________________________________________________________________________________

Sample Run:


Related Solutions

Customer Amount of Tip Amount of Bill Number of Diners Customer Amount of Tip Amount of...
Customer Amount of Tip Amount of Bill Number of Diners Customer Amount of Tip Amount of Bill Number of Diners 1 $ 7.70 $ 46.02 1 16 $ 3.30 $ 23.59 2 2 4.50 28.23 4 17 3.50 22.30 2 3 1.00 10.65 1 18 3.25 32.00 2 4 2.40 19.82 3 19 5.40 50.02 4 5 5.00 28.62 3 20 2.25 17.60 3 6 4.25 24.83 2 21 3.90 58.18 1 7 0.50 6.25 1 22 3.00 20.27 2...
How can I configure the button in this tip calculator to calculate the total using the...
How can I configure the button in this tip calculator to calculate the total using the entires for the bill and tip percentage? I'm using Visual Studio 2019 Xamarin.Forms Main.Page.xaml <?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:d="http://xamarin.com/schemas/2014/forms/design" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="Accomplish_2.MainPage" BackgroundColor="Gray" Padding="5"> <StackLayout> <!-- Place new controls here --> <Label Text="Tip Calculator" HorizontalOptions="Center" VerticalOptions="Center" FontSize="Title" FontAttributes="Bold"/> <BoxView BackgroundColor="LightPink" HeightRequest="3"></BoxView>    <Entry Placeholder="Bill Total" Keyboard="Numeric" x:Name="billTotal"></Entry>    <Entry Placeholder="Tip Percentage" Keyboard="Numeric" x:Name="tipPercent"></Entry> <Button Text="Calculate" Clicked="Button_Clicked"></Button>    </StackLayout> </ContentPage> Everything above...
[Javascript] Create a function that gets the total amount and percentage of covid case data for...
[Javascript] Create a function that gets the total amount and percentage of covid case data for each Age Group in the covid cases data set(which contains the property "Age Group" in each case array). Age Groups: 'younger than 18', 'between 19 to 28 Years', 'between 29 to 38 Years','between 39 to 48 Years','between 49 to 58 Years','between 59 to 68 Years','between 69 to 78 Years','between 79 to 88 Years', and'older than 89' the function getSummaryOfAges(data) should return an Object with...
Based on the descriptions given below, write the JavaScript codes to calculate the amount to be...
Based on the descriptions given below, write the JavaScript codes to calculate the amount to be paid for books purchased.  Declare all the variables used in this program.  Ask the user to key-in the book code using a prompt() method. Store the value in a variable named book_code.  Ask the user to key-in the number of books purchased using a prompt() method. Store the value in a variable named book_qty.  Ask the user whether they have...
This program will calculate the amount for a semester bill at The University of Nantucket. Part...
This program will calculate the amount for a semester bill at The University of Nantucket. Part 1: Create a class Course.java: The class has non-static instance variables: private String department private int courseNumber private int courseCredits private double courseCost The class must have a default constructor which will set values as follows: department = 0 courseNumber = 0 courseCost = 0 The class must a non-default constructor which will set values as follows: department = value passed to constructor courseNumber...
1. Calculate the compound amount. Use the compound amount formula and a calculator. (Round your answer...
1. Calculate the compound amount. Use the compound amount formula and a calculator. (Round your answer to two decimal places.) P = $1700, r = 5% compounded semiannually, t = 12 years 2. Calculate the future value. (Round your answer to two decimal places.) P = $8000, r = 5.5% compounded quarterly, t = 3 years 3.Calculate the future value. (Round your answer to two decimal places.) P = $29,000, r = 8% compounded monthly, t = 5 years
What is the total amount of healthcare expenditures in the US? Provide a specific amount in dollars and percentage with respect to GDP.
  What is the total amount of healthcare expenditures in the US? Provide a specific amount in dollars and percentage with respect to GDP. During the first part of the semester we have spent a great deal of time reviewing general concepts of economics to build the foundation to understand specific issues of the healthcare sector. What general economic assumptions do not apply to healthcare? Explain why. Define the concept of adverse selection and explain why it is important in...
Is there a way to design an experiment to calculate the total amount of weight or...
Is there a way to design an experiment to calculate the total amount of weight or force a material (such as fabrics/toilet paper) can support before breaking that does not revolve around the usage of tensile strength test or extremely large masses? Can we design an experiment that can be small scaled?
Purchases: Eagle View receives the utility bill for the month. The total amount due is $500,...
Purchases: Eagle View receives the utility bill for the month. The total amount due is $500, payable net 20. Eagle View also purchases 50 units of inventory at $400 each and 50 more toolkits at $4 each. Payroll: Eagle View pays its employees for the fifth two weeks of business (November 26 through December 9). The gross pay is $2,000, the employee taxes are $500 and the employer taxes are $500. Part of this has already been accrued in November....
---------------------------------------------------------------------------------------------------------------- C++ //code a program for the following the given Instruction. Geometry Calculator 1. Calculate the...
---------------------------------------------------------------------------------------------------------------- C++ //code a program for the following the given Instruction. Geometry Calculator 1. Calculate the Area of a Circle 2. Calculate the Area of a Rectangle 3. Calculate the Area of a Triangle 4. Quit Enter your choice (1-4): If the user enters 1, the program should ask for the radius of the circle and then display its area. Use 3.14159 for pi. #03   If the user enters 2, the program should ask for the length and width of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT