Full version: jsB@nk » Calculation » Math » Factors
URL: https://www.javascriptbank.com/factors.html
Use JavaScript to find out if a number entered is odd or even and the factors of that number.
Full version: jsB@nk » Calculation » Math » Factors
URL: https://www.javascriptbank.com/factors.html
<SCRIPT LANGUAGE="JavaScript">//Nicholas John Sullivan ([email protected])<!-- Beginfunction calc() {var dnum = ((eval(document.res.inpa.value)) / 2);var i;var pol;var inum = (Math.round(dnum));if (inum == dnum) {document.res.rses.value="Number: " + (eval(document.res.inpa.value)) + " is Even\n\n";}else {document.res.rses.value="Number: " + (eval(document.res.inpa.value)) + " is Odd\n\n";}document.res.rses.value += "Factors Are:\n\n";var num = Math.round(eval(document.res.inpa.value));for (i = 2; i < (num / 2); i++) {var chkd = Math.round(num / i);var inn = Math.round(num / i);var outt = (num / i);if (inn == outt && chkd > i) {document.res.rses.value = document.res.rses.value + "(" + (num/i) + "," + i + ")"; } }}function numbersonly() {if (event.keyCode < 48 || event.keyCode > 57) return false;}// End --></script><!-- This script downloaded from www.JavaScriptBank.com Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->
<form name="res"><input type=text value="0" name="inpa" onkeypress="return numbersonly()"><input type=button name="bt1" value="Calculate" onClick="calc()"><br>Results<br><textarea name="rses" cols="20" rows="10" value="nothing"></textarea></form><!-- This script downloaded from www.JavaScriptBank.com Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->