Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>JTQ Distance Calculator</title>
- <script>
- var cityName = ["Indianapolis", "New York", "Tokyo", "London"];
- var distances = [
- [0, 648, 6476, 4000],
- [648, 0, 6760, 3470],
- [6476, 6760, 0, 5956],
- [4000, 3470, 5956, 0],
- ];
- var cityMenu = "\n\n";
- for (var i=0; i < cityName.length; i++)
- cityMenu += i + ") " + cityName[i] + "\n";
- function GetCity(heading)
- {
- var theCity;
- theCity = prompt(heading + cityMenu);
- //Should check that theCity is valid!
- return theCity;
- }
- function main()
- {
- var output;
- var fromCity = GetCity("Please choose a starting city by typing in a number:");
- var toCity = GetCity("Please choose an ending city by typing in a number:");
- var result = distances[fromCity][toCity];
- output = "The distance from " + cityName[fromCity];
- output += " to " + cityName[toCity];
- output += " is " + result + " miles.";
- alert (output);
- }
- </script>
- </head>
- <body onload="main();">
- <h2>JTQ's distance calculator</h2>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment