Web Development 101: the ruby project


#1

When is try to implement the multiply test, the first test for multiply two arguments pass but for multiple arguments fail

this is the calculator_spec.rb

Extra Credit Test-Driving Bonus:

once the above tests pass,

write tests and code for the following:

describe “multiply” do
it “multiplies two numbers” do
expect(multiply(2, 2)).to eq(4)
end
it “multiplies several numbers” do
expect(multiply(2, 2, 2)).to eq(8)
end
end

this is the function definition

def multiply(x, y)
x * y
end


#2

Hey @awaisalikhan

With Javascript you need to match against the arguments being passed in so that you can use them in the function.

When you have a function whose arguments are defined as (x,y) it will only match against the first two arguments. So if you call the function with (1,2,3) x will match to 1, y will match to 2 and 3 will be undefined because nothing can match against it.

You should look into, and consider using the spread syntax to grab all of the arguments in the array

https://devdocs.io/javascript/operators/spread_syntax

You can then consider a function such as reduce to sum that array.

https://devdocs.io/javascript/global_objects/array/reduce

Let us know if you’re still having issues.