Javascript Beginner - Feedback Problems

Asked

Viewed 78 times

0

Why isn’t this code returning the right answer? I’m testing through the Chrome console. In the tests I change the value of var, but nothing happens.

Following the example of the class I am doing, everything is correct. I am forgetting some detail?

Follows the code:

var kills = 2;

		if (kills = 0){
			console.log('Seu noob!');
		
		}else if (kills > 1 && kills <= 3){
			console.log('Killer!');
		
		}else if (kills > 4 && kills <= 10) {
			console.log('Violent!');
		
		}else if (kills > 11){
			console.log('Unstoppable!');
		};

  • 2

    if (kills = 0){ you are making an assignment and not a comparison ==

  • Wonderful! That was it! Solved!

1 answer

3


You’re assigning a value (kills = 0) within a if (condition).

If you want to compare values, use the ==:

if (kills == 0){}
  • Perfect! That was it! Solved!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.