Programming Examples
JavaScript code that calculates the squares and cubes from 0 to 10
Write a JavaScript that calculates the squares and cubes of the numbers from 0 to 10 and outputs HTML text that displays the resulting values in an HTML table format.Â
Solution
<!DOCTYPE html>
<html>
<head>
<title>Square and Qube of Number</title>
</head>
<body>
<table align="center" border="1" cellpadding="5px" cellspacing="0">
<tr>
<th>Number</th>
<th>Square</th>
<th>Cube</th>
</tr>
<script language="javascript">
for(a=0;a<=10;a++)
{
document.write("<tr><td>"+a+"</td><td>"+(a*a)+"</td><td>"+(a*a*a)+"</td></tr>");
}
</script>
</body>
</html>
Output
