8 practice makes perfect bug?


#1




I am able to call the by_three? method without using the question mark at the end is this just a bug?

I thought to call a method it has to be exact name?


def greeter(name)
  return "Hello " + name
end
greeter("joe")

def by_three?(number)
  if number % 3 == 0
    return true
  else
    return false
  end
end
by_three(99)


#2

I think you write the function like this:

def by_three?(n)
  return n % 3 == 0
end

I may be wrong, because I don't know that much about ruby, but I believe that the question mark is a type of If statement.
like it's going to return true if n is divisible by 3, and false if it's not...
I guess I'll try to look more into it, but my code does work for this function, and my explanation is the only one I can come up with.


#3

Hi @programmer_1111 ,

Refresh the page, then submit your code again. Then you will see that it does not work.

After that, to fix it, change this ...

by_three(99)

... to this ...

by_three?(99)

What explains this strange behavior? Quite likely, you had this recently ...

def by_three(number)

Codecademy remembers the function as it was defined by that name, by_three, as well as by the new name, by_three?. Refreshing the page removes remembered obsolete names, along with others, from memory, thereby enabling a valid reappraisal of your code.


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.