Or Statement

Discussion in 'Javascript' started by BillyZ, Jul 21, 2008.

  1. BillyZ

    BillyZ Guest

    I am implementing a conditional menu. The script below is evaluating
    to see if I am on either of two specific pages. I have done it two
    different way's and both are below.
    Thanks in advance.

    #1 This returns false all the time.

    if (pageName == ('nacPartnerPage') || ('networkAccessPage')) {
    nacSecondary = true;
    } else {
    nacSecondary = false
    };

    #2 This returns true all the time.
    if (pageName == 'nacPartnerPage' || 'networkAccessPage') {
    nacSecondary = true;
    } else {
    nacSecondary = false
    };
    BillyZ, Jul 21, 2008
    #1
    1. Advertising

  2. BillyZ

    Henry Guest

    On Jul 21, 4:48 pm, BillyZ <> wrote:
    <snip>
    > #1 This returns false all the time.
    >
    > if (pageName == ('nacPartnerPage') || ('networkAccessPage')) {

    <snip> ^ ^

    Unlikely. Without those two inner parentheses it might return false
    all of the time. With them the above is equivalent to your second
    attempt.
    Henry, Jul 21, 2008
    #2
    1. Advertising

  3. BillyZ

    Tim Streater Guest

    In article
    <>,
    BillyZ <> wrote:

    > I am implementing a conditional menu. The script below is evaluating
    > to see if I am on either of two specific pages. I have done it two
    > different way's and both are below.
    > Thanks in advance.
    >
    > #1 This returns false all the time.
    >
    > if (pageName == ('nacPartnerPage') || ('networkAccessPage')) {


    This is not how you do an "or". You need to write:

    if ((pageName=='nacPartnerPage') || (pageName=='networkAccessPage')) {
    Tim Streater, Jul 21, 2008
    #3
  4. In comp.lang.javascript message <449a2b9e-c3f5-4447-b323-18f8aa2e763d@34
    g2000hsf.googlegroups.com>, Mon, 21 Jul 2008 08:48:53, BillyZ
    <> posted:

    >if (pageName == ('nacPartnerPage') || ('networkAccessPage')) {
    > nacSecondary = true;
    > } else {
    > nacSecondary = false
    > };


    Additionally, there is no need to write
    if (A) B = true ; else B = false
    which should be written
    B = A
    and is reversed by
    B = !A

    It's a good idea to read the newsgroup c.l.j and its FAQ. See below.

    --
    (c) John Stockton, nr London UK. ?@merlyn.demon.co.uk IE7 FF2 Op9 Sf3
    news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
    <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
    <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
    Dr J R Stockton, Jul 22, 2008
    #4
  5. Tim Streater wrote:
    > BillyZ <> wrote:
    >> I am implementing a conditional menu. The script below is evaluating
    >> to see if I am on either of two specific pages. I have done it two
    >> different way's and both are below.
    >> Thanks in advance.
    >>
    >> #1 This returns false all the time.
    >>
    >> if (pageName == ('nacPartnerPage') || ('networkAccessPage')) {

    >
    > This is not how you do an "or". You need to write:
    >
    > if ((pageName=='nacPartnerPage') || (pageName=='networkAccessPage')) {


    Another, less compatible possibility[1] is

    if (pageName in {nacPartnerPage: 1, networkAccessPage: 1}) {

    (provided one has not augmented Object.prototype).

    But the `if' statement really is superfluous here:

    nacSecondary = (one_of_the_suggested_boolean_expressions);


    PointedEars
    ___________
    [1] <http://PointedEars.de/es-matrix#i>
    --
    Prototype.js was written by people who don't know javascript for people
    who don't know javascript. People who don't know javascript are not
    the best source of advice on designing systems that use javascript.
    -- Richard Cornford, cljs, <f806at$ail$1$>
    Thomas 'PointedEars' Lahn, Jul 22, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    802
  2. Jay McGavren
    Replies:
    11
    Views:
    1,130
    Alan Krueger
    Jan 16, 2006
  3. tedsuzman
    Replies:
    2
    Views:
    7,079
    Michel Claveau, résurectionné d'outre-bombe inform
    Jul 21, 2004
  4. Ted
    Replies:
    1
    Views:
    461
    Duncan Booth
    Jul 22, 2004
  5. Replies:
    21
    Views:
    1,053
    Giannis Papadopoulos
    Aug 2, 2005
Loading...

Share This Page