learn-co-curriculum/method-arguments-lab
Objectives
Define a method that takes in an argument and uses that argument in the method body.
Define a method that takes in two arguments and uses both arguments in the method body.
Instructions
You'll be coding your methods in lib/introduction.rb
.
The #introduction
Method
#introduction
MethodRun the test suite to get started. To do that, run learn
or learn test
in your terminal. Let's take a look at the first error:
Wow, that's a lot of information. The important part for us though is the line that tells us what kind of error we are experiencing:
Looks like our test is expecting to test a method called #introduction
. Let's define that method in lib/introduction.rb
.
Now we'll run our test suite again. You should see the following error:
Once again the important part of this error message is the part where the type of error is described:
Now we have an ArgumentError. The test is trying to call our #introduction
method with an argument (notice it says 1
) but we haven't defined our method to take in any arguments, the for 0
part of the error message.
Let's fix that now:
Run the test again and you'll see the following:
Now the important part of our error message is here:
Our test is expecting our method to puts
out the exact phrase, using the value of the name
argument that the method is called with.
Let's fix that:
Run the test again and we should be passing the first of our two tests. Use the test output and the procedure we just followed to get the second test passing.
The #introduction_with_language
Method
#introduction_with_language
MethodDefine a method, #introduction_with_language
that takes in two arguments, name
and language
and outputs the phrase: `"Hi, my name is #{name} and I am learning to program in #{language}."
Last updated