Navigation




Exercise: Inversion

Write a program that inverts a number. For example, the inversion of 5 is 1/5 is 0.2.

The program should act like this.

If the user leaves the input field blank, enters a non-numeric value, or enters zero, the user should receive an error message. Try it and see how the program should work.

Use jQuery to access the input field and show the error message. You can download jQuery and store it in the same directory as your solution. Right-click here and select Save. You can include jQuery in your Web page with this:

<script type="text/javascript" src="jquery-1.3.1.min.js"></script>

< Back to Introducing JS