Or Statement

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • BillyZ

    Or Statement

    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 == ('nacPartnerPag e') || ('networkAccess Page')) {
    nacSecondary = true;
    } else {
    nacSecondary = false
    };

    #2 This returns true all the time.
    if (pageName == 'nacPartnerPage ' || 'networkAccessP age') {
    nacSecondary = true;
    } else {
    nacSecondary = false
    };
  • Good Man

    #2
    Re: Or Statement

    BillyZ <bill.zabel@gma il.comwrote in news:449a2b9e-c3f5-4447-b323-
    18f8aa2e763d@34 g2000hsf.google groups.com:
    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 == ('nacPartnerPag e') || ('networkAccess Page')) {
    nacSecondary = true;
    } else {
    nacSecondary = false
    };
    >
    #2 This returns true all the time.
    if (pageName == 'nacPartnerPage ' || 'networkAccessP age') {
    nacSecondary = true;
    } else {
    nacSecondary = false
    };
    >
    you need to be more explicit

    if((pageName==' nacPartnerPage' ) || (pageName=='net workAccessPage' )) {
    //blah blah blah
    }

    Comment

    • Henry

      #3
      Re: Or Statement

      On Jul 21, 4:48 pm, BillyZ <bill.za...@gma il.comwrote:
      <snip>
      #1 This returns false all the time.
      >
      if (pageName == ('nacPartnerPag e') || ('networkAccess Page')) {
      <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.

      Comment

      • Tim Streater

        #4
        Re: Or Statement

        In article
        <449a2b9e-c3f5-4447-b323-18f8aa2e763d@34 g2000hsf.google groups.com>,
        BillyZ <bill.zabel@gma il.comwrote:
        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 == ('nacPartnerPag e') || ('networkAccess Page')) {
        This is not how you do an "or". You need to write:

        if ((pageName=='na cPartnerPage') || (pageName=='net workAccessPage' )) {

        Comment

        • Dr J R Stockton

          #5
          Re: Or Statement

          In comp.lang.javas cript message <449a2b9e-c3f5-4447-b323-18f8aa2e763d@34
          g2000hsf.google groups.com>, Mon, 21 Jul 2008 08:48:53, BillyZ
          <bill.zabel@gma il.composted:
          >if (pageName == ('nacPartnerPag e') || ('networkAccess Page')) {
          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.c om/faq/index.html>.
          <URL:http://www.merlyn.demo n.co.uk/js-index.htmjscr maths, dates, sources.
          <URL:http://www.merlyn.demo n.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.

          Comment

          • Thomas 'PointedEars' Lahn

            #6
            Re: Or Statement

            Tim Streater wrote:
            BillyZ <bill.zabel@gma il.comwrote:
            >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 == ('nacPartnerPag e') || ('networkAccess Page')) {
            >
            This is not how you do an "or". You need to write:
            >
            if ((pageName=='na cPartnerPage') || (pageName=='net workAccessPage' )) {
            Another, less compatible possibility[1] is

            if (pageName in {nacPartnerPage : 1, networkAccessPa ge: 1}) {

            (provided one has not augmented Object.prototyp e).

            But the `if' statement really is superfluous here:

            nacSecondary = (one_of_the_sug gested_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$8 300dec7@news.de mon.co.uk>

            Comment

            Working...