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


Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2026 Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Best Website and Software Company in Allahabad