Document Object Model (DOM)

Simply JavaScript Slideshow

JavaScript Temperature Converter

JavaScript DOM Challenges

JavaScript Distance Converter

Download the start files and add the JavaScript necessary to make this distance converter take a number of miles and convert it to a number of kilometers and display the conversion in the grey area at the bottom of the design.

Round the conversion to three decimal places. The equation for converting miles to kilometers is that 1 mile equals 1.609344 kilometers.

If the user does not put in a number, or puts something other than a number in the text field, have the result text say, “please enter a number”.

Optional Challenge

To really impress, figure out how to make it so that if the user presses the “K” key on the keyboard, the converter switches to converting kilometers to miles. If the user presses the “M” key on the keyboard, it switches back to converting miles to kilometers. The equation you need for converting kilometers to miles is 1 kilometer equals 0.621371192 miles. Again, round to three decimal places.