<!DOCTYPE html>
<html>
<head>
<title>Factorial calculation with a recursive function</title>
<style type="text/css">
p {margin: 0;}
</style>
<script type="text/javascript">
var output= "";
var input = parseInt(window.prompt("Please input the number"));
document.writeln("<h1> Factorials of 0 to " + input + " </h1>");
function calculateFactorials (){
for (var i=0; i <= input; i++){
output += "" + i + "! = " + factorial(i) + "<br>";
document.getElementById("hasil").innerHTML=output;
}
}
function factorial (angka){
if(angka == 0) {
return 1;
} else {
return angka * factorial(angka - 1);
}
}
window.addEventListener("load", calculateFactorials, false);
</script>
</head>
<body>
<div id="results"><p id="hasil"></div>
</body>
</html>
<html>
<head>
<title>Factorial calculation with a recursive function</title>
<style type="text/css">
p {margin: 0;}
</style>
<script type="text/javascript">
var output= "";
var input = parseInt(window.prompt("Please input the number"));
document.writeln("<h1> Factorials of 0 to " + input + " </h1>");
function calculateFactorials (){
for (var i=0; i <= input; i++){
output += "" + i + "! = " + factorial(i) + "<br>";
document.getElementById("hasil").innerHTML=output;
}
}
function factorial (angka){
if(angka == 0) {
return 1;
} else {
return angka * factorial(angka - 1);
}
}
window.addEventListener("load", calculateFactorials, false);
</script>
</head>
<body>
<div id="results"><p id="hasil"></div>
</body>
</html>
Thanks for reading & sharing RZDev: Belajar Programming!
0 comments:
Post a Comment