Please answer me this javascript question. Need answer to part (2)
Don't make irrelevant comments please.
Answers
The problem is solved using JavaScript.
<!DOCTYPE html>
<html>
<head>
<title>
JavaScript.
</title>
</head>
<body>
<table id="tt" border=1>
<tr>
<td>S.No.</td>
<td>Number.</td>
<td>Factorial.</td>
</tr>
</table>
<style>
table{
border-collapse: collapse;
}
td{
padding: 12px;
}
</style>
<script>
function factorial(a){
if(a==1)
return 1;
return a*factorial(a-1);
}
var a=parseInt(prompt("Please enter first number: "));
var b=parseInt(prompt("Please enter second number: "));
var c=1;
for(var i=a;i<=b;i++,c++){
var r= document.getElementById("tt").insertRow(i-a+1);
var c1 = r.insertCell(0);
var c2 = r.insertCell(1);
var c3 = r.insertCell(2);
c1.innerHTML = c;
c2.innerHTML = i;
c3.innerHTML = factorial(i);
}
</script>
</body>
</html>
- By default, a table is created with 1 row and 3 columns, containing S.No, Number and Factorial.
- Now we have inserted a new row and new columns. Inside the columns, we have filled the required data using innerHTML property. Hence, the problem is solved.
See attachment for output.