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 trialThomas Hoffmann
903 PointsTask 2: I can't figure out how to code it.
Hi there again, it seems I am having trouble with this lesson
I have been trying to figure out a code to explain that isWinner should not be 10 but I can't seem to figure out the answer and its frustrating me. Every time I am told I can't assign the string to a Int value.
let isWinner = totalScore let totalScore !=10
// Enter your code below
var initialScore = 8
let totalScore = ++initialScore
let isWinner =
2 Answers
Jason Anders
Treehouse Moderator 145,860 PointsThomas, you've almost got it, you just have some extra code where you shouldn't.
You will be assigning the Boolean result to the constant isWinner
, so your part is correct. The second part (after the = sign) doesn't get any type of var or let. It is a Boolean comparison that will evaluate to True or False.
So, what you need is there, just delete the extras.
let isWinner = totalScore != 10
Here totalScore !=
is asking if the Total Score does not equal 10. In this case it doesn't, so it will return True.
Make sense?
Tobias Helmrich
31,603 PointsHey Thomas,
you almost got it right and actually you already have the solution if you remove some code.
let isWinner = totalScore let totalScore !=10
Here you just have to remove totalScore let
so you have
let isWinner = totalScore != 10
which should work. You just have to assign the result of the comparison between totalScore
and 10 with the inequality operator to the isWinner
constant.
Also note that the increment and decrement operators ++
and --
will be removed in Swift 3 so make sure to use +=
and -=
in the future.
I hope that helps! :)
Thomas Hoffmann
903 PointsHi Tobias,
Thank you very much, looks like I tend to overcomplicate things... I guess Swift is simpler than I tend to make it.
Have a great day!
Thomas Hoffmann
903 PointsThomas Hoffmann
903 PointsThank you Jason, your explanation helps me better understand the logic behind the code. Like I wrote earlier, I should think more straight forward in these situations.