-2

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

isherwood
  • 58,414
  • 16
  • 114
  • 157
  • Have you used some tool to see the exact differences between your code and the example (working) code? Have you tried to run your code in a local environment to see its actual output? Is the code you show us here an exact, full and complete copy-paste of the code submitted to whatever site you use for checking? – Some programmer dude Dec 03 '21 at 14:00
  • So not "literally", I guess. :) Voting to close as a typo. – isherwood Dec 03 '21 at 14:05
  • I guess I founded now that the fisrt level had to star on 0 and not 1. Thanks – Raquel Lima Dec 03 '21 at 14:10
  • Neither of the two code snippets will explicitly handle the case when `charmanderLevel == 0`. And `charmanderLevel` will never be equal or larger than `100` (as [`Math.random()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random) will never return `1`). So both attempts are flawed. – Some programmer dude Dec 03 '21 at 14:11
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Dec 08 '21 at 10:59
  • I t is resolved! Thanks – Raquel Lima Dec 09 '21 at 13:37

1 Answers1

1

I had to use a file comparer to see the slightly detail.

In case of level > 100, your message is "Charizard is good as it gets", you miss the little "as" of the right answer.

This answer show how to compare files in vscode.