Try it yourself! I have no idea what I'm doing wrong


#1



https://www.codecademy.com/courses/ruby-beginner-en-L3ZCI/0/5?curriculum_id=5059f8619189a5000201fbcb#


The instructions are:
Define your own method, double, that accepts a single parameter and yields to a block. Then call it with a block that multiplies the number parameter by 2. You can double any number you like!

So my code is:

def double(param)
    #my problem was here
    yield param
end

n = 2
double(n) {n * 2}


According to the console, the method is returning 4, as it should, but I'm still getting the error from codecademy:
Oops, try again. Did you create a method called double?

Being that I did create such a method, I'm not really sure what's wrong here.

EDIT: Resolved


#2

So may we take it that you wrote the following to resolve this?


def double(x)
    yield x
end
double(21) { |n| n * 2 }

#3

My "yield" statement lacked an argument, so I added "param" after "yield"


#4

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