Question

In: Computer Science

<!DOCTYPE html> <html> <body> <script> // // A car's miles-per-gallon (MPG) can be calculated with the...

<!DOCTYPE html>
<html>
<body>
<script>
//
// A car's miles-per-gallon (MPG) can be calculated with the following formula:
//
//      MPG=Milesdriven/Gallonsofgasused
//
// Write a program that asks the user for the number of miles driven and the 
// gallons of gas used. It should then call a function to calculate and return 
// the car's MPG and display the result.
//

function calculateMPG(miles, gas) {

/////////////////////////////////////////////////////////////////////////////////
// Insert your code between here and the next comment block.  Do not alter     //
// any code in any other part of this file.                                    //
/////////////////////////////////////////////////////////////////////////////////

        
/////////////////////////////////////////////////////////////////////////////////
// Insert your code between here and the previous comment block.  Do not alter //
// any code in any other part of this file.                                    //
/////////////////////////////////////////////////////////////////////////////////

}

var milesDriven = prompt('How many miles have you driven? ');
var gasUsed = prompt('How much gas have you used driving that far? ')

alert('You car is getting ' + calculateMPG(milesDriven, gasUsed) + ' MPG.');

</script>
</body>
</html>

Solutions

Expert Solution

Below is the solution:

<!DOCTYPE html>
<html>
<body>
<script>

//function to calculate the MPG
function calculateMPG(miles, gas) {
var MPG=miles/gas; //formua to calculate the MPG (MPG=Milesdriven/Gallonsofgasused)
return MPG; //return
}

var milesDriven = prompt('How many miles have you driven? '); //ask the user to enter the miles driven
var gasUsed = prompt('How much gas have you used driving that far? ') //ask the user to enter the gas used

alert('You car is getting ' + calculateMPG(milesDriven, gasUsed) + ' MPG.'); //call the function inside the aler to calculate the MPG

</script>
</body>
</html>

sample output:


Related Solutions

<!DOCTYPE html> <html> <body> <script> // // The colors red, blue, and yellow are known as...
<!DOCTYPE html> <html> <body> <script> // // The colors red, blue, and yellow are known as the primary colors because they // cannot be made by mixing other colors. When you mix two primary colors, you // get a secondary color, as shown here: // // When you mix red and blue, you get purple. // When you mix red and yellow, you get orange. // When you mix blue and yellow, you get green. // // Design a program...
A car manufacturer claims that the miles per gallon (mpg) of all its midsize cars can...
A car manufacturer claims that the miles per gallon (mpg) of all its midsize cars can be modeled with a normal model with N(33, 1.70). What proportion of cars have miles per gallon less than 31.2 [P(x ≤31.2 mpg)]? What proportion of cars will have miles per gallon greater than 36 [P(x ≥36 mpg)]? What proportion of cars will have miles per gallon less than 30[P(x ≤30 mpg)]? What proportion of cars will have miles per gallon between 32 and...
It is necessary for an automobile producer to estimate the number of miles per gallon (mpg)...
It is necessary for an automobile producer to estimate the number of miles per gallon (mpg) achieved by its cars. Suppose that the sample mean for a random sample of 5050 cars is 30.630.6 mpg and assume the standard deviation is 3.63.6 mpg. Now suppose the car producer wants to test the hypothesis that μμ, the mean number of miles per gallon, is 31.631.6 against the alternative hypothesis that it is not 31.631.6. Conduct a test using a significance level...
It is necessary for an automobile producer to estimate the number of miles per gallon (mpg)...
It is necessary for an automobile producer to estimate the number of miles per gallon (mpg) achieved by its cars. Suppose that the sample mean for a random sample of 5050 cars is 30.630.6 mpg and assume the standard deviation is 3.63.6 mpg. Now suppose the car producer wants to test the hypothesis that μμ, the mean number of miles per gallon, is 31.631.6 against the alternative hypothesis that it is not 31.631.6. Conduct a test using a significance level...
Your car gets 22 miles per gallon (MPG) at 55 miles per hour (MPH) and 18...
Your car gets 22 miles per gallon (MPG) at 55 miles per hour (MPH) and 18 MPG at 65 MPH. At what speed should you make a 450-mile trip 1. If gas costs $2.95 per gallon and your time is worth $17/hour? 2. If gas costs $3.80 per gallon and your time is worth $11.5/hour? 3. If gas costs $4.75 per gallon and your time is worth $8.9/hour? 4. Building an Excel spreadsheet to calculate the total trip cost for...
Your car gets 25 miles per gallon (mpg) at 60 miles per hour (mph) and 18...
Your car gets 25 miles per gallon (mpg) at 60 miles per hour (mph) and 18 mpg at 70 mph. At what speed should you make a 600-mile trip: 1. If gas costs $3 per gallon and your time is worth $12 per hour? 2. If gas costs $4 per gallon and your time is worth $15 per hour? 3. If gas costs $5 per gallon and your time is worth $10 per hour? 4. Build a spreadsheet to calculate...
Your car gets 29 miles per gallon (mpg) at 60 miles per hour (mph) and 25...
Your car gets 29 miles per gallon (mpg) at 60 miles per hour (mph) and 25 mpg a 70 mph. At what speed should you make a 525-mile trip: If gas costs $3 per gallon and your time is worth $18 per hour If gas costs $4 per gallon and your time is worth $12 per hour If gas costs $5 per gallon and your time is worth $9 per hour
Can someone verify why my code isnt running <!DOCTYPE html> <html> <body bgcolor=aqua text=purple> <script type="text/javascript">...
Can someone verify why my code isnt running <!DOCTYPE html> <html> <body bgcolor=aqua text=purple> <script type="text/javascript"> funtion oldMacVerse(animal, sound) //Assumes: animal is the name of an animal, sound is the sound it makes //Results: displays a version of the song "Old MacDonals Had a Farm" in outputDiv { document.getElementById('outputDiv').innerHTML =    '<p>Old MacDonald had a farm, E-I-E-I-O.<br>' +    'And on that farm he had a ' + animal + ', E-I-E-I-O.<br>' +    'With a ' + sound +...
The manufacturer of a new compact car claims the miles per gallon (mpg) for the gasoline...
The manufacturer of a new compact car claims the miles per gallon (mpg) for the gasoline consumption is mound-shaped and symmetric with a mean of 27.4 mpg and a standard deviation of 12.3 mpg. If 30 such cars are tested, what is the probability the average mpg achieved by these 30 cars will be greater than 28?
A sample of 20 Automobiles was taken and the miles per gallon (MPG), horsepower (HP), and...
A sample of 20 Automobiles was taken and the miles per gallon (MPG), horsepower (HP), and total weight were recorded. Develop a linear regression model to predict MPG… MPG Horsepower Weight 44 67 1844 44 50 1998 40 62 1752 37 69 1980 37 66 1797 34 63 2199 35 90 2404 32 99 2611 30 63 3236 28 91 2606 26 94 2580 26 88 2507 25 124 2922 22 97 2434 20 114 3248 21 102 2812 18...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT