Can´t figure out why this function doesn´t work

Can´t figure out why this function doesn´t work
0

#1

I fail to see why this doesn´t return true. Any ideas?

function checkNumber(num) {
  if( num % num ===1 && num % 1 === num) {
    return true;
  };
}
checkNumber(10);

#2

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.


#3

It does not return true because num % num is 0 and num % 1 is also 0. Remember that % divides two numbers and returns the remainder.


#4

I don’t think that you understand what the % operator does.
num % num will never equal 1 and num % 1 will only equal num if num is 0.


#5

Hahaha, I was just working out that as you said it! I feel so dumb. Thanks a lot!


#6

Thank you, I just realised that.