mercredi 25 juillet 2018

How to correct the output of this jquery code?

This code should print:

  1. if the screen width is < 740 or is 740.
  2. if the screen width is > 740 and the screen width is < 1065
  3. if the screen width is >1065 or is 1065
  4. if the screen width is >1389 or is 1389

But it always shows 2 or 3 randomly when the 4th condition is true.
whats the problem in here? Take a look at the console.

https://codepen.io/code_alex/pen/xJLwpq

var screenWidth = $(window).width();

if(screenWidth < 740 || screenWidth == 740) {
  console.log("1");
} else if(screenWidth > 740 && screenWidth < 1065){
  console.log("2");
} else if(screenWidth > 1065 || screenWidth == 1065) {
  console.log("3");
} else if (screenWidth > 1389 || screenWidth == 1389) {
  console.log("4");
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

Aucun commentaire:

Enregistrer un commentaire