SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Hybrid View

  1. #1
    Non-Member
    Join Date
    Jan 2008
    Location
    N43 44.4824', W079 13.9408
    Posts
    2,220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Array String Write.

    I'd like to know why this is not writing, specifically the last line. I have the array which is fine but I can't get the last line to write.

    Code JavaScript:
    document.write ('<p>The First Author is <strong>');
    	document.write (authors[0] + '</strong></p>');
    	document.write ('<p>The last author is <strong>');
    	document.write (authors[authors.length-1] + '</strong></p>');
    	authors.unshift ('Stan Lee');
    	document.write ('<p>I almost forgot <strong>' + authors[0] '</strong></p>');

  2. #2
    SitePoint Enthusiast
    Join Date
    Jun 2011
    Location
    Dartmouth, MA, USA
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're missing a plus sign between authors[0] and '</strong></p>'.

  3. #3
    Non-Member
    Join Date
    Jan 2008
    Location
    N43 44.4824', W079 13.9408
    Posts
    2,220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Odd the error console is saying I'm missing a bracket in the argument list.

    document.write ('<p>I almost forgot <strong>' authors[0] + '</strong></p>');

  4. #4
    SitePoint Enthusiast
    Join Date
    Jun 2011
    Location
    Dartmouth, MA, USA
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by SiberianHuskey View Post
    Odd the error console is saying I'm missing a bracket in the argument list.
    You'll still need the plus sign before authors[0] too.

  5. #5
    Non-Member
    Join Date
    Jan 2008
    Location
    N43 44.4824', W079 13.9408
    Posts
    2,220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ahhh right. Add the array between two strings, son of a gun.

  6. #6
    SitePoint Enthusiast
    Join Date
    Jun 2011
    Location
    Dartmouth, MA, USA
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yep, sometimes the smallest errors (missing one character, as in this case) will mess you up. Some languages (like Ruby) allow you to concatenate strings by just putting them next to each other in an expression, but in JavaScript you need to separate each string you wish to concatenate with a plus sign.

  7. #7
    Non-Member
    Join Date
    Jan 2008
    Location
    N43 44.4824', W079 13.9408
    Posts
    2,220
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Interesting, I don't know what Ruby can do but I see it is a little more simpler.


Bookmarks

Posting Permissions

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