0

What I thought this code would do is, if i typed non-numbers it would continue prompting me until I finally input a number which it then will output the word "one" on the page.
What it does is if I type a number first it outputs the word "one" on the page. If i type a non-number it continuously loops even if I put a number afterwards.

And this is a learning experiment. So please be nice

<script type="text/javascript">
var luckynumber = prompt("Whats the number?");
luckynumber = parseInt(luckynumber);
	while(isNaN(luckynumber)) {
		prompt("Numbers only!")
	}
	if (! isNaN(luckynumber)) {
		document.write('one')
	}
</script>

Edited by skald89: n/a

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by skald89
0

Change your while loop to the following:

while(isNaN(luckynumber)) {
	luckynumber = prompt("Numbers only!");
}

Also, please remember inserting semicolons at the end of your statements.

0

Change your while loop to the following:

while(isNaN(luckynumber)) {
	luckynumber = prompt("Numbers only!");
}

Also, please remember inserting semicolons at the end of your statements.

Thank you. I think I understand it a little better now. I was also unaware that "luckynumber = prompt("Numbers only!");" was an end of a statement.

0

I didnt want to make another post.
is there a difference between + and , ?
like in these 2 codes

document.write('hello' + 'bye');
document.write('hello' , 'bye');
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.