lundi 4 janvier 2021

If-statements, Why does it alert yes instead of the other options? [closed]

Hi there fellow programmers!

Can someone please write comments on the code line by line that explaines why it will turn out as it does?

I try to get a grip of the Javascript but it’s not easy for me.

All help is much appreciated!

var num1 = 10;
var num2 = 20;

if (num1 == 10) {
  num2 = num1;
}

if (num2 > 10) {
  console.log("Bear!");

} else if (num1 < 5) {
  console.log("Cat!");
  num1 = 5;
}

if (num1 <= num2 && num2 <= 30) {
  console.log("yes!");
} else {
  console.log("no!");
}

Aucun commentaire:

Enregistrer un commentaire