Since I had the Programming Concepts class this exercise was not totally new (but still fun to do). I used the if(isNan(parseInt(variableName))) method to check for a true number (not NaN). If the value entered was NaN, a message telling the person to "enter a number" is returned to the function call and displayed using a document.write statement and the program ends. If the number was NOT NaN then the program drops into the else if test and checks to see if the entered value is an integer using the else if (parseInt(intPrompt)) statement. If it is an integer then the program returns the variable message of "You entered number blah, blah, blah... and the total". I added a second variable that is the result of the entered value converted to an integer using the variableName = parseInt(firstVariableName) to catch people who enter a number followed by letters. I don't understand why the isNan does not catch these type of bogus entries, especially because it recognizes the entry as Nan, but it isn't so instead I am stripping off any characters following a number(s). |