Last active
June 13, 2018 03:52
-
-
Save AminBusiness/b730d87248daf366bb581d9f67f318a8 to your computer and use it in GitHub Desktop.
JS Bin// source https://jsbin.com/wumoges
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const MINMILES = 1; | |
const MAXMILES = 1000; | |
const MINGALLS = 1; | |
const MAXGALLS = 100; | |
function main() | |
{ | |
var again = true; | |
while(again) | |
{ | |
var miles = inputMilesDriven(); | |
var gals = inputGallonsUsed(); | |
var mpg = calculateMPG(miles, gals); | |
wanna = prompt("Do you wish to run the program again? ", "Y"); | |
first = wanna.charAt(0).toUpperCase(); | |
if(first !== "Y") | |
{ | |
again = false; | |
} | |
} | |
} | |
function inputMilesDriven() | |
{ | |
var invalidMilesDriven = true; | |
var md = 0.0; | |
while(invalidMilesDriven) | |
{ | |
md = parseFloat(prompt("Please enter a miles driven between " + MINMILES + " and " + MAXMILES, "345")); | |
while((isNan(md)) || (md < MINMILES) || (md > MAXMILES)) | |
{ | |
alert ("Invalid miles driven input!!!") | |
md = parseFloat(prompt("Please enter a miles driven between " + MINMILES + " and " + MAXMILES, "345")); | |
} | |
invalidMilesDriven = false; | |
} | |
} | |
function inputGallonsUsed() | |
{ | |
var invalidGallonsUsed = true; | |
var gu = 0.0; | |
while(invalidGallonsUsed) | |
{ | |
gu = parseFloat(prompt("Please enter a gallons used between " + MINGALLS + " and " + MAXGALLS, "15")); | |
while((isNan(gu)) || (gu < MINMILES) || (gu > MAXMILES)) | |
{ | |
alert ("Invalid miles driven input!!!") | |
gu = parseFloat(prompt("Please enter a gallons used between " + MINMILES + " and " + MAXMILES, "345")); | |
} | |
invalidGallonsUsed = false; | |
} | |
return gu; | |
} | |
function calucateMPG(miles, gallons) | |
{ | |
return (miles / gallons).toFixed(2); | |
} | |
function displayResults(miles, gallons, mpg) | |
{ | |
alert("Miles Driven: " + miles + "\n" + | |
"Gallons Used: " + gallons + "\n" + | |
"Miles/Gallon: " + mpg); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
const MINMILES = 1; | |
const MAXMILES = 1000; | |
const MINGALLS = 1; | |
const MAXGALLS = 100; | |
function main() | |
{ | |
var again = true; | |
while(again) | |
{ | |
var miles = inputMilesDriven(); | |
var gals = inputGallonsUsed(); | |
var mpg = calculateMPG(miles, gals); | |
wanna = prompt("Do you wish to run the program again? ", "Y"); | |
first = wanna.charAt(0).toUpperCase(); | |
if(first !== "Y") | |
{ | |
again = false; | |
} | |
} | |
} | |
function inputMilesDriven() | |
{ | |
var invalidMilesDriven = true; | |
var md = 0.0; | |
while(invalidMilesDriven) | |
{ | |
md = parseFloat(prompt("Please enter a miles driven between " + MINMILES + " and " + MAXMILES, "345")); | |
while((isNan(md)) || (md < MINMILES) || (md > MAXMILES)) | |
{ | |
alert ("Invalid miles driven input!!!") | |
md = parseFloat(prompt("Please enter a miles driven between " + MINMILES + " and " + MAXMILES, "345")); | |
} | |
invalidMilesDriven = false; | |
} | |
} | |
function inputGallonsUsed() | |
{ | |
var invalidGallonsUsed = true; | |
var gu = 0.0; | |
while(invalidGallonsUsed) | |
{ | |
gu = parseFloat(prompt("Please enter a gallons used between " + MINGALLS + " and " + MAXGALLS, "15")); | |
while((isNan(gu)) || (gu < MINMILES) || (gu > MAXMILES)) | |
{ | |
alert ("Invalid miles driven input!!!") | |
gu = parseFloat(prompt("Please enter a gallons used between " + MINMILES + " and " + MAXMILES, "345")); | |
} | |
invalidGallonsUsed = false; | |
} | |
return gu; | |
} | |
function calucateMPG(miles, gallons) | |
{ | |
return (miles / gallons).toFixed(2); | |
} | |
function displayResults(miles, gallons, mpg) | |
{ | |
alert("Miles Driven: " + miles + "\n" + | |
"Gallons Used: " + gallons + "\n" + | |
"Miles/Gallon: " + mpg); | |
} | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript"> | |
const MINMILES = 1; | |
const MAXMILES = 1000; | |
const MINGALLS = 1; | |
const MAXGALLS = 100; | |
function main() | |
{ | |
var again = true; | |
while(again) | |
{ | |
var miles = inputMilesDriven(); | |
var gals = inputGallonsUsed(); | |
var mpg = calculateMPG(miles, gals); | |
wanna = prompt("Do you wish to run the program again? ", "Y"); | |
first = wanna.charAt(0).toUpperCase(); | |
if(first !== "Y") | |
{ | |
again = false; | |
} | |
} | |
} | |
function inputMilesDriven() | |
{ | |
var invalidMilesDriven = true; | |
var md = 0.0; | |
while(invalidMilesDriven) | |
{ | |
md = parseFloat(prompt("Please enter a miles driven between " + MINMILES + " and " + MAXMILES, "345")); | |
while((isNan(md)) || (md < MINMILES) || (md > MAXMILES)) | |
{ | |
alert ("Invalid miles driven input!!!") | |
md = parseFloat(prompt("Please enter a miles driven between " + MINMILES + " and " + MAXMILES, "345")); | |
} | |
invalidMilesDriven = false; | |
} | |
} | |
function inputGallonsUsed() | |
{ | |
var invalidGallonsUsed = true; | |
var gu = 0.0; | |
while(invalidGallonsUsed) | |
{ | |
gu = parseFloat(prompt("Please enter a gallons used between " + MINGALLS + " and " + MAXGALLS, "15")); | |
while((isNan(gu)) || (gu < MINMILES) || (gu > MAXMILES)) | |
{ | |
alert ("Invalid miles driven input!!!") | |
gu = parseFloat(prompt("Please enter a gallons used between " + MINMILES + " and " + MAXMILES, "345")); | |
} | |
invalidGallonsUsed = false; | |
} | |
return gu; | |
} | |
function calucateMPG(miles, gallons) | |
{ | |
return (miles / gallons).toFixed(2); | |
} | |
function displayResults(miles, gallons, mpg) | |
{ | |
alert("Miles Driven: " + miles + "\n" + | |
"Gallons Used: " + gallons + "\n" + | |
"Miles/Gallon: " + mpg); | |
}</script></body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment