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

Mark Weinberg
Mark Weinberg
3,002 Points

Assign the constant E inside of the Math module to the instance variable @e.

I'm having trouble with Challenge Task 1 of 3 which is to "Assign the constant E inside of the Math module to the instance variable @e." Can someone show me what the correct code is so I can learn from it?

math.rb
@pi = nil
@e  = nil
@sqrt = nil

module Math::E
  @e = nil
end

4 Answers

In the previous video, in the code samples, you see how to do this:

puts Math::E          # => 2.718281828459045
puts Math::PI         # => 3.141592653589793
puts Math.sqrt(9)     # => 3.0
puts Math.cos(1)      # => 0.5403023058681398
puts Math.hypot(2, 2) # => 2.8284271247461903
puts Math.log(2, 10)  # => 0.30102999566398114
puts Math.log(2, 12)  # => 0.2789429456511298

The problem says: "Assign the constant E inside of the Math module to the instance variable @e.".

You need to make @e equal to the constant already defined, E. So the only thing you need to tell Ruby is say which is the module (Math). Then: @e = Math::E

It works this way

module Math

puts Math::E = @e

end

Sean Flanagan
Sean Flanagan
33,235 Points

Thank you Omar and Mia for your input. It's a big help. I've upvoted both posts.