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 2021 CCC Practice Test Hindi Python Programming Tutorials 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 Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz