Full version: jsB@nk » Calculation » Common Factors Calculator
URL: https://www.javascriptbank.com/common-factors-calculator.html
Enter two integers, then click the button. You will be given a list of common integer factors of the two numbers!
Full version: jsB@nk » Calculation » Common Factors Calculator
URL: https://www.javascriptbank.com/common-factors-calculator.html
<script>// Tom McComb ([email protected])function findFactors() {var f = document.forms[0];var value1 = parseInt( f.composite1.value );var value2 = parseInt( f.composite2.value );if ( isNaN( value1 ) || isNaN( value2 ) ) {alert( "Please enter valid number values" );f.reset();return;}if ( value1 == 0 || value2 == 0 ) {alert( "No common factors" );return;}value1 = Math.abs( value1 );value2 = Math.abs( value2 );var answer = "1";for ( var x = 2; x < Math.min( value1, value2 ); x ++ ) {var check1 = value1 / x;if ( check1 == Math.round( check1 ) ) { var check2 = value2 / x;if ( check2 == Math.round( check2 ) ) {answer += ", " + x;}}}alert( "value1 = " + value1 + "\nvalue2 = " + value2 + "\nCommon Factors: " + answer );}</script><!-- This script downloaded from www.JavaScriptBank.com Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->
<form><table border=1 cellspacing=1 cellpadding=3 width=300 align=center><tr><td colspan=2><font face=Arial size=2>Enter two numbers, then click the button to find the common integer factors of both numbers.</font></td></tr><tr><td><font face=Arial size=1>Composite 1:</font></td><td><input type=text name=composite1></td></tr><tr><td><font face=Arial size=1>Composite 2:</font></td><td><input type=text name=composite2></td></tr><tr><td colspan=2 align=right><input type=button value="Find Common Factors" onclick="findFactors();"></td></tr></table></form><!-- This script downloaded from www.JavaScriptBank.com Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->