...

View Full Version : Help with Random HTML generator (arrays, etc)



freechus9
07-08-2003, 07:33 AM
I am pretty new to JavaScript, so I probably messed this up or left something out. But I have no clue what I did! Here's the code:

<SCRIPT LANGUAGE="JavaScript1.2">

var a = Math.round(Math.random())

var array = new Array(2)
array[0] = <a href="http://www.aratronix.com"><img src="aratronix.jpg" border="1" bordercolor="000000"></a><b>Aratronix</b> is a computer company whose layout was completed in June of 2003.;
array[1] = More completed projects to come!;

document.write('+array[a]+');

</SCRIPT>

A syntax error keeps on showing up, and I don't know what's wrong. Could someone please tell me?

beetle
07-08-2003, 09:34 AM
Your mistakes
1) didn't delimit string literals (the single quotes I added)
2) Calculate random int at wrong time (also, use .floor(), not .round())
3) Broken concatenation attempt in document.write() that was also unecessary

<SCRIPT LANGUAGE="JavaScript1.2">

var arr = new Array(2)
arr[0] = '<a href="http://www.aratronix.com"><img src="aratronix.jpg" border="1" bordercolor="000000"></a><b>Aratronix</b> is a computer company whose layout was completed in June of 2003.';
arr[1] = 'More completed projects to come!';

var a = Math.floor(Math.random() * arr.length)

document.write(arr[a]);

</SCRIPT>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum