- Nov 18, 2005
- 28,799
- 359
- 126
So I'm using codecademy to start learning Ruby.
The instructions for this short exercise:
"Define two methods in the editor:
1. 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.)
2. A by_three? method that takes a single integer parameter, number, and returns true if that number is evenly divisible by three and false if not."
Note the greeter method instructions to return a string greeting.
I've tried a few different things and the code simulator does not agree with me, saying "it looks like your greeter method prints to the console instead of using return."
How do I display a string that isn't displayed in the console? That's what it appears to be saying. Return a string, but don't dare display the string? Because see below, I didn't use print or puts.
I tried the below, also didn't work:
As well as the below:
And a few variations of the above.
Looking up online, this simple thing should work. But, hell, now the last two aren't even displaying that string in the console. Yet the simulator is yelling at me that the method prints to the console instead of using return. lol
Is this just a simulator running afoul of itself, as opposed to an actual violation of the intended code?
edit: but the below allows me to proceed, stating I finished the section:
Which seems to not accomplish the original intent of the instructions.
The instructions for this short exercise:
"Define two methods in the editor:
1. 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.)
2. A by_three? method that takes a single integer parameter, number, and returns true if that number is evenly divisible by three and false if not."
Note the greeter method instructions to return a string greeting.
I've tried a few different things and the code simulator does not agree with me, saying "it looks like your greeter method prints to the console instead of using return."
How do I display a string that isn't displayed in the console? That's what it appears to be saying. Return a string, but don't dare display the string? Because see below, I didn't use print or puts.
Code:
def greeter(name)
return "Hi, #{name}!"
end
I tried the below, also didn't work:
Code:
def greeter(name)
var = "Hi, #{name}!"
return var
end
As well as the below:
Code:
def greeter(name)
return "Hi, " + name
end
And a few variations of the above.
Looking up online, this simple thing should work. But, hell, now the last two aren't even displaying that string in the console. Yet the simulator is yelling at me that the method prints to the console instead of using return. lol
Is this just a simulator running afoul of itself, as opposed to an actual violation of the intended code?
edit: but the below allows me to proceed, stating I finished the section:
Code:
def greeter(name)
return
end
Which seems to not accomplish the original intent of the instructions.
Last edited:
