0

Write a program that creates a text file that contains a power of two table in HTML format. The file could be called "twoPowerTable.html". When it is viewed with a browser you will see something like:

Power of 2 Value
0 1
1 2
2 4
3 8
4 16
5 32
6 64
7 128
8 256
9 512
10 1024

The file should start with something like:

<html><head>
<title>Powers of Two</title>
</head>
<body>
<table border cellpadding=5>
<tr><th>Power of 2</th><th>Value</th></tr>

And end with:

</table>
</body></html>

Each line of the table looks like:

<tr><td>0</td><td>1</td></tr>

I don't know why it can't show the table but i am doing the Exercises in this website: http://chortle.ccsu.edu/java5/Notes/chap83/progExercises83.html

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by rajarajan2017
0

Solution:

<html>
<head>
<script type="text/javascript">
function insRow()
{
var temp=1;
for (i=1;i<=11;i++)
{
	var x=document.getElementById('myTable').insertRow(0);
	var y=x.insertCell(0);
	var z=x.insertCell(1);
	y.innerHTML=i-1;
	if (i==1) {
		z.innerHTML=eval(temp);
	}else{
		temp+=temp;
		z.innerHTML=eval(temp);
	}
}
}
</script>
</head>

<body>
<table id="myTable" border="1">
<tr align="center">
<td colspan="2">End of the Table</td>
<td></td>
</tr>
</table>
<br />
<input type="button" onclick="insRow()" value="Insert row">
</body>
</html>

I dont know how to insert after a row

Edited by rajarajan2017: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.