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 trialCarrie Kwok
3,045 PointsQuestion about loop
I wonder why the output IS NOT:
o <--- this o is from y'O'U
o <--- this o is from g'O't
o <--- this o is from 'O'h
h<--- this h is from O'h'
?
1 Answer
Chris Freeman
Treehouse Moderator 68,441 PointsThe for
loop is operating on the string "You got this!"
. Each character in this string is assigned to letter
before running the if
statement. The if
statement check to see if the letter is contained in the string "oh
". The characters "o" and "h" are not compared to themselves. So the output would be:
# comparing "Y"
# comparing "o" --> output "o"
# comparing "u"
# comparing " "
# comparing "g"
# comparing "o" --> output "o"
# comparing "t"
# comparing " "
# comparing "t"
# comparing "h" --> output "h"
# comparing "i"
# comparing "s"
# comparing "!"
Post back if you need more help. Good luck!!
boi
14,242 Pointsboi
14,242 PointsI honestly find it hard to understand your question. Is your question about why the output is "ooh" instead of just "oh" or "o"?