View Full Version : For loop

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"
<html xmlns="http://www.w3.org/1999/xhtml">

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

for (var i = 1; i <= m; i++)
txt +=<table>Hello</table>+'<br>';


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


This is HTML basic....

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>';

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum