Question

In: Computer Science

Write a defining table and a JavaScript program that computes and outputs the rate of change...

Write a defining table and a JavaScript program that computes and outputs the rate of change of a price. The program must allow the user to enter a previous price and a current price. The formula for the rate of change is

rateOfChange =  currPrice - prevPrice

prevPrice

Your program should allow a user to enter real numbers such as 7.54. If you wish, you may use the following HTML code in your program.

<!DOCTYPE HTML>
<html lang="en-us">
<head>
<meta charset="utf-8">
<title>Rate of Change</title>
<script>

// Your JavaScript function belongs here.

</script>
</head>

<body>
    <h1>Rate of Change</h1>
    Previous Price <input type="text" id="prevPrice"><br>
    Current Price <input type="text" id="currPrice"><br>
    <button type="button" onclick="computeRateOfChange()">Rate of Change</button><br>
    Rate of Change <div id="rate"></div>
</body>
</html>
Test Cases
Inputs Output
previous current
70.5 72.2 0.0241
96 91.4 -0.0479

Solutions

Expert Solution

<!DOCTYPE HTML>
<html lang="en-us">
<head>
<meta charset="utf-8">
<title>Rate of Change</title>
<script>

function computeRateOfChange(){
   var previousPrice = parseInt(document.getElementById("prevPrice").value);
   var currentPrice = parseInt(document.getElementById("currPrice").value);
   var rateOfChange = currentPrice-previousPrice;
   document.getElementById("rate").innerHTML=rateOfChange;
}

</script>
</head>

<body>
<h1>Rate of Change</h1>
Previous Price <input type="text" id="prevPrice"><br>
Current Price <input type="text" id="currPrice"><br>
<button type="button" onclick="computeRateOfChange()">Rate of Change</button><br>
Rate of Change
   <div id="rate"></div>
</body>
</html>

NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.

I AM HERE TO HELP YOUIF YOU LIKE MY ANSWER PLEASE RATE AND HELP ME IT IS VERY IMP FOR ME


Related Solutions

Write a defining table and a computer program that computes and outputs the volume of a...
Write a defining table and a computer program that computes and outputs the volume of a torus with inner radius a and outer radius b. A doughnut is an example of a torus. Your program must read the inner radius and outer radius from two text fields and display the volume in a div. The formula for the volume of a torus is v =  π2(a + b)(a - b)2 4 where v is the volume, π is the constant pi,...
Write a JavaScript program that computes the average of a collection of numbers and then outputs...
Write a JavaScript program that computes the average of a collection of numbers and then outputs the total number of values that are greater than the average. An A grade is any score that is at least 20% greater than the average. The B grade is any score that is not an A, but is at least 10% greater than the average. An F grade is any score that is at least 20% less than the average. The D grade...
Write a FORTRAN program that computes the average of a collection of numbers and then outputs...
Write a FORTRAN program that computes the average of a collection of numbers and then outputs the total number of values that are greater than the average. An A grade is any score that is at least 20% greater than the average. The B grade is any score that is not an A, but is at least 10% greater than the average. An F grade is any score that is at least 20% less than the average. The D grade...
Write the programs in JavaScript: Write a program that reads a text file and outputs the...
Write the programs in JavaScript: Write a program that reads a text file and outputs the text file with line numbers at the beginning of each line.
Write a javascript program that computes the total cost for a five year car lease. The...
Write a javascript program that computes the total cost for a five year car lease. The program starts with a monthly leasing amount and a yearly increase in percent. The program then outputs the total amount paid for each year and the total overall cost of the lease.
Write the below code to use HTML and JavaScript. 1. a) Write a JavaScript program to...
Write the below code to use HTML and JavaScript. 1. a) Write a JavaScript program to display the current day and time. b) Write a JavaScript program to print the contents of the current window.   c) Write a JavaScript program where the program takes a random integer between 1 to 10 d) Write a JavaScript program to calculate multiplication and division of two numbers (input from the user). e)Write a JavaScript program to create a new string from a given...
Write the following java program. Desc: The program computes the cost of parking a car in...
Write the following java program. Desc: The program computes the cost of parking a car in a public garage at the rate $5.00/hour. The client will always be charged for whole hours. For example, if a car parked for 2 hours and 1 minute, the client will be charged for 3 hours. Input: User inputs the entry time and exit time in 24-hr clock format (hh:mm) Output: The enter and exit times, the length of time the car is parked...
Write a Python program that computes the income tax for an individual. The program should ask...
Write a Python program that computes the income tax for an individual. The program should ask the user to enter the total taxable income for the year. The program then uses the tax bracket (as shown below) to calculate the tax amount. This is based on a progressive income tax system which is how income tax is calculated in the U.S. As a result, this for example means that only income above $500,001 is taxed at 37%. Income of lower...
Write a Python program that computes the income tax for an individual. The program should ask...
Write a Python program that computes the income tax for an individual. The program should ask the user to enter the total taxable income for the year. The program then uses the tax bracket (as shown below) to calculate the tax amount. This is based on a progressive income tax system which is how income tax is calculated in the U.S. As a result, this for example means that only income above $500,001 is taxed at 37%. Income of lower...
C++ program Overloaded Hospital Write a c++ program that computes and displays the charges for a...
C++ program Overloaded Hospital Write a c++ program that computes and displays the charges for a patient’s hospital stay. First, the program should ask if the patient was admitted as an inpatient or an outpatient. If the patient was an inpatient, the following data should be entered: The number of days spent in the hospital The daily rate Hospital medication charges Charges for hospital services (lab tests, etc.) The program should ask for the following data if the patient was...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT