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 trialAaron Figueroa
2,860 PointsHow do I format this if/ elsif statement to be correct?
It gives me 2 variables. One for car speed and another for speed limit. the answer is supposed to read true if the car speed is greater than the speed limit but unless I change the car speed... that statement will never read true. I have changed the speeds, order, and I even tried to take not def "too_fast:" I don't know what I'm doing wrong.
def "too_fast:"
car_speed = 55
speed_limit = 60
if car_speed > speed_limit
puts true
elsif car_speed < speed_limit
puts false
end
2 Answers
William Li
Courses Plus Student 26,868 PointsHi, Aaron, you shouldn't use the puts statement here, instead, you should assign the true/false to the variable too_fast
# Write your code here
if car_speed > speed_limit
too_fast = true
elsif car_speed < speed_limit
too_fast = false
end
Also, you have to delete this first line in your code, it serves no purpose and will definitely cause syntax error
def "too_fast:"
Paul Jackson
7,585 PointsHi Aaron you don't need to use the puts since you are not outputting anything to the console. You simply need to assign the true or false value to the too_fast variable. Also, you don't need the elsif condition because you only have two possible conditions:
- You are going over the speed limit
- You are not going over the speed limit
Using a if/else statement like this will work just fine.
car_speed = 55
speed_limit = 60
if car_speed > speed_limit
too_fast = true
else
too_fast = false
end
Hope this helps!