I need to write a script that finds the smallest of several non-negative intergers while using a sentinel-controlled lopp (-1 to exit window prompt).
I know something's clearly wrong since the window prompt never disappears. Been trying for hours and I really don't feel like starting over. Any advice or help would be amazing since this is due very soon.
Thanks a lot
<?xml version = "1.0" encoding = "utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title></title> <p>Keep entering postive integer numbers, I will find the smallest. When you are done enter -1 to quit.</p> <script type="text/javascript"> <!-- var itemcount; var i; var small=0; var cal; number = window.prompt("Enter a number:"); var count = parseInt(number); var myarray = new Array(count); for(i=0;i<count;i++) { myarray[i]= window.prompt("Enter a number:"); if (number == -1) break; } cal=myarray[0]; for(i=0;i<count;i++) { if(parseInt(myarray[i])< cal) cal= myarray[i]; } document.writeln("Smallest of all input numbers is: " + cal); document.writeln("<br/>") document.writeln("Click Refresh (or Reload) to run this script again.") // --> </script> </head> <body> </body> </html>