vendredi 29 mai 2020

If number > value, change number to another value [closed]

I want if the value of number is more than 5, it will automatically change it's value to 0 again. I tried the following code, but it is not working! It continues to 5, 6, 7, 8 ......

& One more thing how to change src as 1 .png , 2 .png , 3 .png (With file extension)

Please help :( Thank you in advance!

var number = 0;
$(window).keydown(function(e) {

  //left arrow key//
  if (e.keyCode == 37) {
    number--;
  }

  //right arrow key//
  if (e.keyCode == 39) {
    number++;
  }

  //back to first//
  if (number > 5) {
    number == 0;
  }

  $("#keymap").attr('src', number);

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>

<img id='keymap' src='1.png'>

Aucun commentaire:

Enregistrer un commentaire