Factors of an input number

Factors are numbers which divide the number evenly.

Factors of 12 are 1, 2, 3, 4, 6, 12
Factors ( of a number ) are numbers which when divide the number they leave 0 as reminder

Enter a number here


Output here
<html>
<head>
<title></title>
</head>
<body>
<input type="text" name="t1" id="t1">
<input type="button" value="Submit" onclick="factor()">
<div id=d1></div>
<script type="text/javascript">
function factor(){
x=document.getElementById("t1").value
x=parseInt(x)
if(Number.isInteger(x)){
str='';
//Highest divisor can be less than half of the input number
x1=Math.ceil(x/2)
for(i=2;i<=x1;i++){
if(x%i==0){
str = str + i + ',' 
}
}
document.getElementById('d1').innerHTML="Factors are:  " + str
}else{
document.getElementById('d1').innerHTML="Enter an Integer  "	
}	
}
</script>
</body>
</html>
isInteger()Checking if input number is integer or not
parseInt()function to convert string to number
Next lower value of any decimal number JavaScript Basic JavaScript variable
JavaScript Math Reference
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com







    Post your comments , suggestion , error , requirements etc here




    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer