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


CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online Exam Quiz O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Best Website and Software Company in Allahabad Website development Company in Allahabad