...

View Full Version : For loop



digic25
05-08-2006, 04:37 AM
I need to create a for loop with a random number from 1-10 that will create hello in a table with cells on whatever number the script generates.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled</title>
</head>

<body>
<script type="text/javascript">
var n = Math.round(1 + Math.random()* 10);

for (var i = 1; i <= m; i++)
{
txt +=<table>Hello</table>+'<br>';
}
document.write(txt)
</script>

</body>
</html>

Kor
05-08-2006, 09:55 AM
hey... Your table needs at least a row and a cell !!

<table>
<tr>
<td>
</td>
</tr>
</table>

This is HTML basic....

Beagle
05-08-2006, 03:11 PM
also, txt should be declared and assigned a value prior to concatenating to it, and your saving your random number in 'n' but looping until 'm', that should be fixed.

Also, you need your html in quotes, and as Kor said you need proper table structure. Here's a slightly improved script. If you need help with the rest, let us know.



<script type="text/javascript">
var n = Math.round(1 + Math.random()* 10);
var txt = '';
for (var i = 1; i <= n; i++)
{
txt += '<tr><td>Hello</td></tr>';
}
document.write(txt)
</script>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum