Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby Ruby Modules Ruby Core Modules Math

What's the problem with my sqrt() in ruby math challenge ?

I'm using the sqrt method but still have a problem :-|

math.rb
@pi = nil
@e  = nil
@sqrt = nil
module Math
Math::PI = @pi
Math::E = @e
Math.sqrt(9) = @sqrt
end

1 Answer

Hi.

Well your error is this line:

Math.sqrt(9) = @sqrt    //this is not correct because this means you are setting the value to Math.sqrt(9) to the value of @sqrt

Just swap this line and your code should look like this:

@pi = nil
@e  = nil
@sqrt = nil
module Math
  Math::PI = @pi
  Math::E = @e
end

 @sqrt = Math.sqrt(9)

Be careful - In programming when you declare a variable the variable is passed the value thats on the right side of =

Hope this helped.

Hi , I did this inside the module and I got error. Thank you for your quick response :)

Welcome :)