Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well, there are two big problems I see right off the bat. First of all, the following syntax is invalid JavaScript:</p> <pre><code>var onoffB = (); </code></pre> <p>I think what you mean there is to have an undefined state for <code>onoffB</code>, which your'e better off doing with:</p> <pre><code>var onoffB = null; </code></pre> <p>Secondly, you're using assignment (<code>=</code>) instead of comparison (<code>==</code> or <code>===</code>). (As a rule of thumb, you should always prefer <code>===</code> over <code>==</code> unless you have a very good reason and know what you're doing.) Consider the following:</p> <pre><code>var x = 3; // *sets* the value of x to 3 var x == 3; // invalid syntax var x === 3; // invalid syntax if( x = 2 ) { print 'x is 2'; } // will *always* print 'x is 2', no matter what // the value of x is; x now has the value 2 // PROBABLY NOT WHAT YOU WANT if( x = 0 ) { print 'x is 0'; } // will *never* print 'x is 0', no matter what // the value of x is; x now has the value 0 // PROBABLY NOT WHAT YOU WANT if( x === 5 ) { print 'x is 5'; } // will only print 'x is 5' if the value of x // is 5; value of x if( x === 0 ) { print 'x is 0'; } // will only print 'x is 0' if the value of x // is 0; value of x unchanged </code></pre> <p>There are a lot of stylistic things I would change about this too. Your code's really difficult to read because of your formatting choices. Furthermore, there's a lot of unnecessarily repeated code. If I were writing this, I would shorten it to the following:</p> <pre><code>switch( document.getElementById("button1").value ) { case 'On': // do stuff break; case 'Off': // do stuff break; case 'Auto': // do stuff break; default: // probably an error condition; show message, maybe? break; } </code></pre> <p>If you really need the value of the on/off/auto button, you can set it inside the <code>case</code> bodies.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload