I am doing some coding challenges at code wars and ran into this one asking me to make a method that takes a number and determines if it is a prime number or not. If it is prime the method should return "true" if the number is not prime it should return "false".
The method passes every introductory test and each number I can think to throw at it but continually kicks back two tests as incorrect. At this point I'm curious if I am not understanding something about the testing process?
This is my code:
def isPrime(num)
counter=2 #is incremented with every time until loop loops
until counter>999999999999999 do
if num.abs <2
return false
elsif num.abs % counter == 0 && num.abs!=counter
return false
else
return true
end#if
counter+=1
end#
end```
and this is the feed back that code wars is sending back to me
isPrime
Should have isPrime defined.
Test Passed
Should return false for numbers less than 2.
Test Passed: Value == false
Test Passed: Value == false
Test Passed: Value == false
Should return false for non-prime numbers.
Test Passed: Value == false
Test Passed: Value == false
Expected: false, instead got: true # THESE ARE THE TESTS THAT FAIL
Expected: false, instead got: true # THESE ARE THE TESTS THAT FAIL
Should return true for prime numbers.
Test Passed: Value == true
Test Passed: Value == true
Test Passed: Value == true
Test Passed: Value == true
Test Passed: Value == true
Also I checked here page for help on the algorithm.
Any help is greatly appreciated.