Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-08-2003, 06:33 AM   PM User | #1
freechus9
New to the CF scene

 
Join Date: Jul 2003
Location: Oak Brook IL
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
freechus9 is an unknown quantity at this point
Help with Random HTML generator (arrays, etc)

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?
__________________
I love food.
freechus9 is offline   Reply With Quote
Old 07-08-2003, 08:34 AM   PM User | #2
beetle
Senior Coder

 
Join Date: Aug 2002
Posts: 3,467
Thanks: 0
Thanked 0 Times in 0 Posts
beetle has a little shameless behaviour in the past
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
Code:
<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>
__________________
My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
“Minds are like parachutes. They don't work unless they are open”
“Maturity is simply knowing when to not be immature”
beetle is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:27 AM.


Advertisement
Log in to turn off these ads.