Hello,
On Sep 13, 2014, at 9:48, Cyril G. [email protected]
wrote:
I’m a beginner and have started Ruby on codecademy.com.
I was told to do something on codecademy which is giving me problems:
Define two methods in the editor:
A greeter method that takes a single string parameter, name, and returns a
string greeting that person. (Make sure to use return and don’t use print or
puts.)
A by_three? method that takes a single integer parameter, number, and
returnstrue if that number is evenly divisible by three and false if not.
Nice. Your code has a syntax error. You need to add an end to line 10,
in order to close the scope. Thats a very common mistake when writing
code, usually editors will complain a priori, or will let you know
that something is wrong using syntax highlighting. In Code Academy you
are writing code in the browser so, I dont remember if the syntax
highlighting works as expected.
return false
end
When I run it, it tells me there is a problem with the greeter method. I’ve
tried multiple things, but nothing seems to work. I should say that the
codecademy.com console expects you to code it exactly how they want it, else, it
will return an error. Some other things I tried
Here is the error when I run the code above: test.rb:11: syntax error,
unexpected end-of-input, expecting keyword_end
The error explicitly states that you missed an end keyword. The line
line 11 is the line where the code gets executed.
Here is the code as it should be:
Greeter program
def greeter(name)
return "Hey " + name
end
def by_three?(number)
if number % 3 == 0
return “true!”
else
return false
end
end
def greeter(name)
return “Hey” + name
end
name("Phoebe)
You didnt define a method called name. Your method is called greeter!
Goes like greeter(Phoebe)
In order to run this code for CodeAcademy you might have to run
name(Phoebe), but in order to see the output in console/terminal you
should add puts, lil puts greeter(Phoebe).
Thanks!
Have a nice day.
Panagiotis (atmosx) Atmatzidis
email: [email protected]
URL: http://www.convalesco.org
GnuPG ID: 0x1A7BFEC5
gpg --keyserver pgp.mit.edu --recv-keys 1A7BFEC5
“As you set out for Ithaca, hope the voyage is a long one, full of
adventure, full of discovery […]” - C. P. Cavafy