Instructions
Create a function called greet that takes a name parameter and returns
"Hello, {name}!" where {name} is replaced with the actual name.
Use string interpolation with #{variable} inside double quotes.
Hints:
- Use string interpolation: "Hello, #{name}!"
- Parameters go in parentheses after the function name
- Make sure to use double quotes for interpolation
Your Code
def greet(name)
"Hello, #{name}!"
end
RSpec.describe "greet function" do
it "greets Alice" do
expect(greet("Alice")).to eq("Hello, Alice!")
end
it "greets Bob" do
expect(greet("Bob")).to eq("Hello, Bob!")
end
it "greets World" do
expect(greet("World")).to eq("Hello, World!")
end
end
Results
Click "Run Tests" to see results