Question
create an application interface as shown below that calculates not only the miles per gallon, but also the average miles per gallon. 1. Open the
create an application interface as shown below that calculates not only the miles per gallon, but also the average miles per gallon.
1. Open the respective html, CSS files given in this assignment and build upon the structure by writing an internal Javascript code to make the above interface work.
2. Declare two global variables named totalMiles and totalGallons and assign them starting values of zero.
(Like this, right after you add the "use strict" directive: var totalMiles = 0, totalGallons = 0;)
3. For each valid user entry, add the miles to the totalMiles variable and add the gallons to the totalGallons variable.
4. Calculate the average miles per gallon using the CalculateMPG function, and store the result in the text box with avg_mpg as its id.
------------------
html code:
var $ = function (id) {
return document.getElementById(id);
}
var calculateMPG = function(miles, gallons) {
}
var processEntries = function () {
var miles = parseFloat($("miles").value);
var gallons = parseInt($("gallons").value);
}
}
window.onload = function () {
}
Calculate Miles Per Gallon
Css File:
body {
font-family: Arial, Helvetica, sans-serif;
background-color: white;
width: 450px;
margin: 0 auto;
padding: 0 2em 1em;
border: 3px solid blue;
}
h1 {
color: blue;
margin-bottom: .25em;
}
label {
float: left;
width: 11em;
text-align: right;
}
input {
margin-left: 1em;
margin-bottom: .5em;
margin-right: .5em;
width: 11em;
}
span {
color: red;
}
Calculate Miles Per Gallon Miles Driven: 372.4 Gallons of Gas Used: 13.7 Miles Per Gallon 28.6 Avg. Miles Per Gallon 29.4 Calculate MPGStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started