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


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

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


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

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


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


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