35 lines
1.0 KiB
HTML
35 lines
1.0 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<title>Miles Per Gallon Calculator</title>
|
|
<link rel="stylesheet" href="mpg.css">
|
|
</head>
|
|
<body>
|
|
<main>
|
|
<h1>The Miles Per Gallon Calculator</h1>
|
|
<script>
|
|
"use strict";
|
|
|
|
// get miles driven from user
|
|
let miles = parseFloat(prompt("Enter miles driven"));
|
|
miles = miles.toFixed(2)
|
|
|
|
// get gallons used from user
|
|
let gallons = parseFloat(prompt("Enter gallons of gas used"));
|
|
gallons = gallons.toFixed(2);
|
|
|
|
// calculate mpg
|
|
const mpg = (miles/gallons).toFixed(2);
|
|
|
|
// display results
|
|
const html = "<p>Miles driven = " + miles + "</p>" +
|
|
"<p>Gallons of gas = " + gallons + "</p>" +
|
|
"<p>Miles per gallon = " + mpg + "<p>";
|
|
document.write(html);
|
|
</script>
|
|
</main>
|
|
</body>
|
|
</html>
|