-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

6
  • 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? Commented Dec 3, 2021 at 14:00
  • So not "literally", I guess. :) Voting to close as a typo. Commented Dec 3, 2021 at 14:05
  • I guess I founded now that the fisrt level had to star on 0 and not 1. Thanks Commented Dec 3, 2021 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() will never return 1). So both attempts are flawed. Commented Dec 3, 2021 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. Commented Dec 8, 2021 at 10:59

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot for that. Now I was able to find the other error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.