<!DOCTYPE html> <html lang="en"> <head> <title>Prime factors calculator</title> </head> <body> <h1>Prime factors calculator without html.</h1> <script type="text/javascript" for="window" event="onload"> // calc prime factors var inputText, outputText; var prime; // try this factor (only primes will match!) var number; // product of the remaining factors while (true) { outputText = ""; inputText = window.prompt("Please enter a number (or 0 to exit):", "") if ((inputText == null) || (inputText.length == 0) || (inputText == "0")) break; prime = 2; // start with 2 number = parseInt(inputText); while ((number > 1) && (prime * prime <= number)) { if (number % prime != 0) { // try the next factor (slowly) prime += 1; } else { // found a factor ! outputText = outputText + " " + prime; number = number / prime; } // if } // while if (number > 1) { // the last factor (a prime) is here. outputText = outputText + " " + number; } window.alert("The factors of " + inputText + " are:" + outputText); } // while </script> <hr /> <p>Programming the old (80's) way, that noone expects on web application.</p> <p>Reload this page to start the calculator again. Press <Esc> to exit.</p> <p>This page is part of the <a href="http://ajaxaspects.blogspot.com/">http://ajaxaspects.blogspot.com/</a> project.</p> <hr /> </body> </html>
This page is part of the http://www.mathertel.de/ web site.
For updates and discussions see http://ajaxaspects.blogspot.com/.