<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>
<Below this line, add a link to the EXACT exercise that you are stuck at.>
<In what way does your code behave incorrectly? Include ALL error messages.>
Well, I’m an beginner with ruby and here have seen my first experience with this language, and I had like so much it. BTW, my report don’t require much attention, it’s simply a little bug that I have found at the following code of the exercise related to methods.
At the incorrect code, I could identified that the result shown when the parameter “n” is not a Interger it’s correctly as defined in unless method, but also are shown the result saying that the number is prime, not breaking the program. Sorry if I cannot make me understand as fine, but I hope this help to make yet most good the class
# Incorrect Code
def prime(n)
puts "It is not a Interger." unless n.is_a? Integer
is_prime = true
for i in 2..n-1
if n % i == 0
is_prime = false
end
end
if is_prime
puts "#{n} is prime!"
else
puts "#{n} is not prime."
end
end
#End incorrect code
# Correctly code
def prime(n)
unless n.is_a? Integer
puts "It is not a Interger."
else
is_prime = true
for i in 2..n-1
if n % i == 0
is_prime = false
end
end
if is_prime
puts "#{n} is prime!"
else
puts "#{n} is not prime."
end
end
end
# End Correctly code