Calculate Factorial using While loop in JavaScript.

 AIM: 

Source Code:

<!DOCTYPE html>

<html lang="en">

<head>

 <meta charset="UTF-8">

 <meta name="viewport" content="width=device-width, initial-scale=1.0">

 <title>Document</title>

</head>

<body>

 <input type="button" onclick="multi_3n5()" value="click here">

 <script>

 function multi_3n5() {

 var n = parseInt(prompt("Number : "));

 var i=1,f=1;

 while(i<=n){

 f=f*i;

 i++;

 }

 document.write("factorial of the number = "+f);}


 </script>

</body>

</html>

Comments

Popular posts from this blog

Calculator

Simple calculator