Reputation: 190
This code doesn't work, I tried to made a loop.
IF it possible to made return without creating new array and counter, that would be great! I the "basic" lang there were a function goto, that just return to needed line. Maybe something like this in JS?
Here the code.
<script type="text/javascript">
var userAge = new Array ();
var loopCounter;
for (loopCounter = 0; loopCounter > 1; loopCounter++) {
var userAge[loopCounter] = prompt ("Enter your age please!");
if (isNaN(userAge[loopCounter])) {
alert ("Enter Number value please! ");
} else {
if (userAge[loopCounter] == 0) {
alert ("You are a baby");
} else if ((userAge[loopCounter] <0) || (userAge[loopCounter] >=200)) {
alert ("I think you are lying about your age!");
} else {
alert ("That\'s a good age!");
}
}
}
</script>
Upvotes: 0
Views: 53
Reputation: 28455
Your condition is wrong.
loopCounter
initialized to 0
and checking it against > 1
which will always be false. Hence, the loop never runs
for (loopCounter = 0; loopCounter > 1; loopCounter++)
Upvotes: 3