Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jul 2003
    Location
    Oak Brook IL
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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”


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •