Script Categories













Calculators >>> Factors.

Use JavaScript to find out if a number entered is odd or even and the factors of that number.


Results

Add the below code to the <body> section of your page:

<script language="javascript" type="text/javascript">
/* Visit http://www.yaldex.com/ for full source code
and get more free JavaScript, CSS and DHTML scripts! */
<!-- Begin
function 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>
<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>

JavaScript Editor Get Advanced
JavaScript and Ajax Editor,
Validator and Debugger!

1st JavaScript Editor.



Code was highlighted by 1st JavaScript Editor (The Best JavaScript Editor!).

R7


©