JavaScript and condition


In JavaScript’s if else condition, you can use ‘and’ to add more than one condition to check. In the example below, you could see the syntax:

<script>
var firstAnswer = 'correct';
var secondAnswer = 'correct';
if (firstAnswer == 'correct' && secondAnswer=='correct') {
    alert('Both answers are correct.');
}
</script>

From the example above, you could see that by using ‘&&’ sign, you combined the two conditions to check, if both first answer and second answer are correct, it returns the alert that both answers are correct.

Hope this helps! ;)

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Technorati
  • Twitter
  • Yahoo! Bookmarks

  1. No comments yet.
(will not be published)