Full-service Internet Marketing & Web Development
Recent Posts

Sponsors
![]() |
Using a while loopCode Wizard, 12-30-2006 |
Using a while loop to take user input from an alert box (Credit: apress.com)
<script type="text/javascript">
var userNumbers = new Array();
var userInput = 0;
var arrayIndex = 0;
var message = '';
var total = 0;
//loop for as long as the user doesn't input 99
while (userInput != 99) {
userInput = prompt("Enter a number, or 99 to exit","99");
userNumbers[arrayIndex] = userInput;
arrayIndex++;
}
message+='You entered the following:n';
for (var i=0;i<arrayIndex-1;i++){
message+=userNumbers[i]+'n';
total+=Number(userNumbers[i]);
}
message+='Total: ' + total + 'n';
alert(message);
</script>
|
|
Subscribe Now to receive new posts via Email as soon as they come out.
Comments
Post your comments

