If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Enjoy an ad free experience by logging in. Not a member yet? Register.

Be aware that prompts and document.write() are considered obsolete and should be used only for testing purposes. You should really use DOM methods to display a message to your users.

It is a bad idea to use the word name as the name of a variable (you should avoid giving names or id's to your variables/functions/arguments/forms words which are HTML/JavaScript methods/properties/attributes such as name), and particularly so when the variable is supposed to contain a number.

Don't forget that values entered by the user are strings unless/until converted to numbers by one of several different methods. That does not matter too much here, but is often the source of unexpected results.

Last edited by Philip M; 06-25-2014 at 10:41 AM.

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.