vendredi 3 décembre 2021

Comparison operators - if / else if statements

This exercise was already posted here a few years ago How to use comparison operators however the solution presented is not working for me.

The question is:

On the editor to your right you find a variable named charmanderLevel, to which a value between 1 and 100 will be assigned.

Using else if statements print to the console which evolution of Charmander corresponds to that experience level. Consider an else statement if the experience level ever go above 100 that should print 'Charizard is as good as it gets '.

Here's a chart with the evolution which corresponds to each level:

Charmander - 1 to 15 Charmeleon - 16 to 35 Charizard - 36 to 100"

The solution was

var charmanderLevel = Math.ceil(Math.random() * 100);

if (charmanderLevel >= 1 && charmanderLevel <= 15) {
  console.log('Charmander');
} else if (charmanderLevel >= 16 && charmanderLevel <= 35) {
  console.log('Charmeleon');
} else if (charmanderLevel >= 36 && charmanderLevel <= 100) {
  console.log('Charizard');
} else {
  console.log('Charizard is as good as it gets');
}

And I created literally the same

var charmanderLevel = Math.ceil(Math.random() * 100);

if (charmanderLevel >= 1 && charmanderLevel <= 15) {
  console.log("Charmander");
} else if (charmanderLevel >= 16 && charmanderLevel <= 35) {
  console.log("Charmeleon");
} else if (charmanderLevel >= 36 && charmanderLevel <= 100) {
  console.log("Charizard");
} else {
  console.log('Charizard is good as it gets');
}

But my console keeps saying

"Code is incorrect You should only print to the console the Charmander evolution level, nothing else".

They suggested that I opened a new question regarding this to ask to some of you some lights please, why it worked for some and mine is not.

Thanks

Aucun commentaire:

Enregistrer un commentaire