Question:

Javascript If statement ? ?

by  |  earlier

0 LIKES UnLike

<input type='text" name="number" id="number" value="">

How would i make an if statement that gave an alert if the value of the box above wasnt between 1000 and 1999 ?

 Tags:

   Report

4 ANSWERS


  1. Stevie, your second &quot;shorter&quot; way is actually 3 characters longer and is harder to understand for beginners. Nice try though.


  2. The long way:

    var value = document.getElementById(&#039;number&#039;);

    if (value &lt; 1000 || value &gt; 1999) {

    alert(&quot;The value wasn&#039;t between 1000 and 1999.&quot;);

    }

    The short way:

    var value = document.getElementById(&#039;number&#039;);

    (value &lt; 1000 || value &gt; 1999) ? alert (&quot;The value wasn&#039;t between 1000 and 1999.&quot;) : &#039;&#039;;

  3. var value = document.getElementById( &#039;number&#039; ).value;

    if ( value &lt; 1000 || value &gt; 1999 ) {

    alert( &#039;The number was not between 1000 and 1999.&#039; );

    }

  4. try here: http://www.w3schools.com/

Question Stats

Latest activity: earlier.
This question has 4 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.