Javascript problem

Discussion in 'Computer Information' started by Robert Baer, Apr 14, 2014.

  1. Robert Baer

    Robert Baer Guest

    Need a different pair of eyes on this, methinks.


    <script>
    function FindJump(gogo)
    {
    gogo='';
    str=navigator.userAgent; // Agent is unique for our purposes
    /* lotza working code edited out */
    var isGek=str.indexOf("Gecko"); // Presumes is in all variants mentioned
    if (isGek>=0) { gogo='PCbase.html'; }
    var z = gogo;

    // So, if not found, ASSuME we have mobile phone browser
    if (z='') { gogo='Mobile.html'; }
    document.writeln('3 gogo='+gogo+'|<BR>');
    document.writeln('4 z='+z+'|<BR>');
    return 'foo'+z+'||' //gogo;
    };
    </script>

    <script>
    str=navigator.userAgent; // Agent is unique for our purposes
    document.writeln(str+"|<BR>");
    // <a onTimeout="doOut(this, '/'+str', 'sass');return false;"></a><br>
    var jmp=FindJump("hi");
    document.writeln('jmp='+jmp);
    </script>

    /* on a PC, one sees: /* on a mobile phone, one sees:
    3 gogo=PCbase.html| jmp=Mobile.html|
    4 z=|
    jmp=foo||

    */

    For a mobile phone:
    1) What is seen is reasonable, as contents of "str" had been previously
    detected and the proper string was returned earlier in the function.

    For a PC:
    1) Line 3 shows that "z" was not empty; if it was, then "gogo"
    would contain 'Mobile.html'
    2) But line 4 then shows "z" as empty. WTF?
    3) Likewise,the next line shows "z" as empty.
     
    Robert Baer, Apr 14, 2014
    #1
    1. Advertising

  2. Robert Baer

    Paul Guest

    Robert Baer wrote:
    > Need a different pair of eyes on this, methinks.
    >
    >
    > <script>
    > function FindJump(gogo)
    > {
    > gogo='';
    > str=navigator.userAgent; // Agent is unique for our purposes
    > /* lotza working code edited out */
    > var isGek=str.indexOf("Gecko"); // Presumes is in all variants mentioned
    > if (isGek>=0) { gogo='PCbase.html'; }
    > var z = gogo;
    >
    > // So, if not found, ASSuME we have mobile phone browser
    > if (z='') { gogo='Mobile.html'; }
    > document.writeln('3 gogo='+gogo+'|<BR>');
    > document.writeln('4 z='+z+'|<BR>');
    > return 'foo'+z+'||' //gogo;
    > };
    > </script>
    >
    > <script>
    > str=navigator.userAgent; // Agent is unique for our purposes
    > document.writeln(str+"|<BR>");
    > // <a onTimeout="doOut(this, '/'+str', 'sass');return false;"></a><br>
    > var jmp=FindJump("hi");
    > document.writeln('jmp='+jmp);
    > </script>
    >
    > /* on a PC, one sees: /* on a mobile phone, one sees:
    > 3 gogo=PCbase.html| jmp=Mobile.html|
    > 4 z=|
    > jmp=foo||
    >
    > */
    >
    > For a mobile phone:
    > 1) What is seen is reasonable, as contents of "str" had been previously
    > detected and the proper string was returned earlier in the function.
    >
    > For a PC:
    > 1) Line 3 shows that "z" was not empty; if it was, then "gogo"
    > would contain 'Mobile.html'
    > 2) But line 4 then shows "z" as empty. WTF?
    > 3) Likewise,the next line shows "z" as empty.
    >


    if (z=='')...

    Equivalence testing is described here. There's the same problem
    in C, where I occasionally type one "=" instead of two, when
    doing an equivalence check.

    http://javascript.about.com/od/decisionmaking/a/des02.htm

    Your single "=", is an assignment statement.

    Initially, I thought it might be a variable scoping problem,
    until I caught that one.

    Paul
     
    Paul, Apr 14, 2014
    #2
    1. Advertising

  3. Robert Baer

    Robert Baer Guest

    Paul wrote:
    > Robert Baer wrote:
    >> Need a different pair of eyes on this, methinks.
    >>
    >>
    >> <script>
    >> function FindJump(gogo)
    >> {
    >> gogo='';
    >> str=navigator.userAgent; // Agent is unique for our purposes
    >> /* lotza working code edited out */
    >> var isGek=str.indexOf("Gecko"); // Presumes is in all variants mentioned
    >> if (isGek>=0) { gogo='PCbase.html'; }
    >> var z = gogo;
    >>
    >> // So, if not found, ASSuME we have mobile phone browser
    >> if (z='') { gogo='Mobile.html'; }
    >> document.writeln('3 gogo='+gogo+'|<BR>');
    >> document.writeln('4 z='+z+'|<BR>');
    >> return 'foo'+z+'||' //gogo;
    >> };
    >> </script>
    >>
    >> <script>
    >> str=navigator.userAgent; // Agent is unique for our purposes
    >> document.writeln(str+"|<BR>");
    >> // <a onTimeout="doOut(this, '/'+str', 'sass');return false;"></a><br>
    >> var jmp=FindJump("hi");
    >> document.writeln('jmp='+jmp);
    >> </script>
    >>
    >> /* on a PC, one sees: /* on a mobile phone, one sees:
    >> 3 gogo=PCbase.html| jmp=Mobile.html|
    >> 4 z=|
    >> jmp=foo||
    >>
    >> */
    >>
    >> For a mobile phone:
    >> 1) What is seen is reasonable, as contents of "str" had been previously
    >> detected and the proper string was returned earlier in the function.
    >>
    >> For a PC:
    >> 1) Line 3 shows that "z" was not empty; if it was, then "gogo"
    >> would contain 'Mobile.html'
    >> 2) But line 4 then shows "z" as empty. WTF?
    >> 3) Likewise,the next line shows "z" as empty.
    >>

    >
    > if (z=='')...
    >
    > Equivalence testing is described here. There's the same problem
    > in C, where I occasionally type one "=" instead of two, when
    > doing an equivalence check.
    >
    > http://javascript.about.com/od/decisionmaking/a/des02.htm
    >
    > Your single "=", is an assignment statement.
    >
    > Initially, I thought it might be a variable scoping problem,
    > until I caught that one.
    >
    > Paul

    Thanks!
    I also see that an "extra" equals sign forces a type match as well;
    not only for == but also for != .
     
    Robert Baer, Apr 14, 2014
    #3
    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. Iain Challis

    Javascript problem

    Iain Challis, Feb 14, 2004, in forum: Computer Support
    Replies:
    2
    Views:
    409
  2. Mike Walker

    Javascript code problem

    Mike Walker, May 31, 2005, in forum: Computer Support
    Replies:
    6
    Views:
    482
  3. oedin

    javascript problem .....

    oedin, Aug 15, 2006, in forum: Firefox
    Replies:
    0
    Views:
    486
    oedin
    Aug 15, 2006
  4. Muse Groops

    Youtube not working, Javascript problem?

    Muse Groops, Mar 27, 2007, in forum: Computer Support
    Replies:
    8
    Views:
    7,213
    MarkSatterfield
    Oct 30, 2008
  5. Shane

    To Javascript, or not to Javascript

    Shane, Aug 29, 2005, in forum: NZ Computing
    Replies:
    5
    Views:
    469
    Waylon Kenning
    Aug 30, 2005
Loading...

Share This Page