lundi 20 avril 2020

My if statement is showing output as "true" while it is false [duplicate]

I wrote this code with javascript and jquery. I don't find why my if-else doesn't work. It should check character string and output should be accordingly.

var startKey = ["A", "a"];
var key1;

$(document).on("keydown", function(event) {
  key1 = event.key;
  start();
});

function start() {
  console.log(key1);
  console.log(startKey[0]);
  if (key1 == startKey[0] || startKey[1]) {
    console.log(true);
  } else {
    console.log(false);
  }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

Aucun commentaire:

Enregistrer un commentaire