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 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 a program that prompts the user to enter a positive integer and then computes the...
Write a program that prompts the user to enter a positive integer and then computes the equivalent binary number and outputs it. The program should consist of 3 files. dec2bin.c that has function dec2bin() implementation to return char array corresponding to binary number. dec2bin.h header file that has function prototype for dec2bin() function dec2binconv.c file with main function that calls dec2bin and print results. This is what i have so far. Im doing this in unix. All the files compiled...
Write a program that reads in the radius and length of a cylinder and computes volume...
Write a program that reads in the radius and length of a cylinder and computes volume using the following formulas: area = radius * radius * PI volume = area * length
Write a program that computes the tax and tip on a restaurant bill for a patron...
Write a program that computes the tax and tip on a restaurant bill for a patron with $44.50 meal charge. The tax should be 6.75% of the meal cost. The tip should be 15% of the total after adding tax. Display the meal cost, tax amount, tip amount, and total bill on the screen. (I need this to be in OOP using C++)
This is a question on the inputs and outputs on Basic javascript application What is the...
This is a question on the inputs and outputs on Basic javascript application What is the displayed output of the application if the user inputs Are: 1    in the first box, 2 in the second box, 3 in the third box, and 4 in the fourth box Modify the HTML and javascript file in order to Creates an h1 and a span element ii)          Accesses all the html elements, then adds the four input values as strings and sends the...
Write a program that takes in a positive integer as input, and outputs a string of...
Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is: As long as x is greater than 0 Output x % 2 (remainder is either 0 or 1) x = x / 2 Note: The above algorithm outputs the 0's and 1's in reverse order. Ex: If the input is: 6 the output is: 011 6 in binary is...
write a program on c++ that outputs a calendar for a given month in a given...
write a program on c++ that outputs a calendar for a given month in a given year, given the day of the week on which the 1st of the month was. The information in numeric format (months are: 1=Januay, 2=February 3=March, 4= April, 5= May, 6= June, 7= July... etc days are 1=Sunday, 2=Monday, 3= Tuesday, 4= Wednesday, 5= Thursday, 6= Friday and 7= Saturday ). The program output that month’s calendar, followed by a sentence indicating on which day...
IN PYTHON Write a program that takes in a positive integer as input, and outputs a...
IN PYTHON Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is: As long as x is greater than 0 Output x % 2 (remainder is either 0 or 1) x = x // 2 Note: The above algorithm outputs the 0's and 1's in reverse order. You will need to write a second function to reverse the string....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT