Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Done #485

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Done #485

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions lib/triangle.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
class Triangle
# write code here
attr_accessor :leg1, :leg2, :leg3

def initialize(leg1, leg2, leg3)
@leg1 = leg1
@leg2 = leg2
@leg3 = leg3
end

def kind
if @leg1 <= 0 || @leg2 <= 0 || @leg3 <= 0
raise TriangleError
elsif ((@leg1 + @leg2) <= @leg3) || ((@leg1 + @leg3) <= @leg2) || ((@leg2 + @leg3) <= @leg1)
raise TriangleError
elsif @leg1 == @leg2 && @leg2 == @leg3
:equilateral
elsif (@leg1 == @leg2 && leg2 != @leg3) || (@leg1 == @leg3 && @leg2 != @leg3) || (@leg2 == @leg3 && @leg1 != @leg3)
:isosceles
elsif @leg1 != @leg2 && @leg2 != @leg3 && @leg1 != @leg3
:scalene
end
end

class TriangleError < StandardError
puts "The selected values do not produce a valid triangle."
end

end