End conditions based upon user input


#1

Alright, i'm always trying to make FOR loops that end based upon user input.

e.g.

for (var a = 0; a = prompt("Please input a number, and only a number."); a++)
{
//stuff that happens in loop
}

I always end up getting an infinite loop.
I'm slightly confused with why.

p.s. how would one delimit the prompt to ONLY accept numbers (because there are always dicks (like me) out there who like to input strings)?


#2

var userPrompt = function(prompt)
{
if(prompt("Select a NUMBER and type it into the white space please")
=== "")
{
prompt("number please");
}

else
{
return prompt;
}
}
maybe?


#3

First of all @chancecarmichael! Please dont ever use the word you know who im talkin about.


#4

@chancecarmichael,

Let's try changing this around a little.

for (var a = 0; CONDITION ; a++){
  prompt("Please input a number, and only a number."); 
}

If you're trying to only accept a certain number then you can use a while loop or something that cancels on a conditions being completed.

So you could try this:

var a;
if (isNaN(a) == false){
prompt("Please input a number, and only a number."); 
}