Not signed in (Sign In)

SkillShare - A place to discuss Web Standards and Web Design topics

Categories

Vanilla 1.1.9 is a product of Lussumo. More Information: Documentation, Community Support.

    •  
      CommentAuthorjskopek
    • CommentTimeApr 25th 2006
     permalink
    In most programming languages you can write this:

    (statement)
    ? execute if the staement is true
    : execute if it isn't

    if you've got a simple if-else statement. Can you do this in Javascript as well? My console seems to throw an exception at this
    •  
      CommentAuthorJohnRiv
    • CommentTimeApr 25th 2006
     permalink
    Yes ternary operators are valid javascript (I use them a lot). What's your line of code that's throwing the exception?
    • CommentAuthorLuc
    • CommentTimeApr 28th 2006 edited
     permalink
    Can you do it in .asp? I've never seen the shorthand done before in .asp.
    • CommentAuthorgregb
    • CommentTimeApr 28th 2006
     permalink
    i think its a C-like language thing
    so C,C++ java, javascript, actionscript (ECMA 262 maybe)
    •  
      CommentAuthorJJenZz
    • CommentTimeApr 28th 2006
     permalink
    (action/variable) (statement) ? true : false;

    e.g.

    a=1;
    myVar = (a==1) ? "Oh Yes!" : "Not this time";
    document.write(myVar);

    or:

    a=2;
    document.write((a==1) ? "Oh Yes!" : "Not this time");

    .... should all work fine.
Add your comments
    Username Password
  • Format comments as (Help)