Re: JavaScript Note: Blue indicates additions, green comments, red possible removals, and red italic removals
<SCRIPT language="JavaScript" >
var userInput;
var userNumber;
var upperLimit = 20;
userInput = window.prompt('Please enter a number in' + //You need to terminate the string and use the + sign to concatenate the two strings if you're going to go to multiple lines 'the range 1 to ' + upperLimit,'');
userNumber = parseFloat(userInput); //Need the ' to say it's a string and the default value is optional. Since you don't have anything useful in there, you might as well leave it out
while ((userNumber <= 1) || (userNumber >=
upperLimit))
{
UserInput = window.prompt('Please re-enter - number' + 'should be in range 1 to' + upperLimit, ''); //Again terminate the string on the first line and use the + to concatenate. The text on the second line is not as a string so put the single quotes around it. Still nothing useful for the second part. Again, since it's optional, you can leave it out. //You also forget to check for valid input. If the user inputs invalid information the first time, they'll be stuck in an infinite loop. You need code here to fix that.
}
document.write('<BR>'+'Your chosen number was ' + //Why make that two strings? It's not necessary. yourNumberuserNumber); //yourNumber? It's been userNumber throughout the script
</SCRIPT>
It seems your biggest problem is just making a string cover multiple lines. You can always put each string on one line to avoid problems.
Last edited by qtwerp : 06-02-2007 at 04:54 PM.
Reason: cleanup
|