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 trialAdim Ofunne
14,736 PointsSet a variable called "too_fast" equal to "true" if the car_speed is faster than the speed_limit.
Pls i wrote this code for the above question, i want to know if it is the write way to go about it . if No pls correct me.
car_speed = 65
speed_limit = 60
if car_speed > speed_limit
then
too_fast=="true"
else
too_fast=="false"
end
2 Answers
Meg Seegmiller
15,150 PointsHi Adim! You're on the right track, but
- use a single equal (=) sign to SET a value
- boolean values (true / false) do not need to be surrounded by quotation marks
- the "then" keyword is optional (and typically not used) unless your if / else statement is on one line
car_speed = 65
speed_limit = 60
if car_speed > speed_limit
too_fast = true
else
too_fast = false
end
Ari Misha
19,323 PointsHiya Adim! You're making it more obscure than it already is. First off, you cant use "then" and "else" in a potentially one-liner code. Just stick to the instructions in the challenge. Secondly, "true" or "false" are boolean values, not string. Rule 601(okay you caught me there is no such reference or context in programming) about programming, wrap anything in double or single quotes makes it a "string".
This code can be written in one-line:
car_speed = 65
speed_limit = 60
too_fast = true if car_speed > speed_limit