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

Does Ruby can accept Operators?

I tried to used greater than or equal to in my when keyword, but it didn't work. I worked with number.

print "Enter student score [0 - 100] : "
score = gets.to_i
grade = 'unknown'
case score
when score >= 90
  grade = 'A'
when score >= 80
  grade = 'B'
  puts "Great"
when score >= 70
  grade = 'C'
when score >= 60
  grade = 'D'
else
  grade = 'Not Passed.'
end

if grade == 'Not Passed.'
  puts "Sorry, your score was : #{score}. In that case, you are #{grade}."
else
  puts "Congrats. Your grade is : #{grade}."
end

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey Fadli,

I haven't run any tests on this, but I think it may have something to do with your conditions. In the first one, you are checking if "grade" is equal to or greater that 90 which will assign an "A". However, the next one is checking if it is greater than or equal to 80 which will give a "B"... the problem here is that greater that or equal to 80 could also be greater than or equal to 90. (You see the conflict?).

Try adjusting your conditional to be something like greater than or equal to AND less than 90.

:dizzy: