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 trialSONU PRABHAKAR
2,039 Pointsproblem regarding win or lose if you score 10 or anything but 10...
solve this.....plz
// Enter your code below
var initialScore = 8
let totalScore = ++initialScore
// i have solved the first one but second problem regarding win or lose if you score
//equal or anything but 10??? solve this problem if you can.
1 Answer
Tobias Helmrich
31,603 PointsHey there,
for the second task you have to compare totalScore
to 10 using the is not equal operator (!=) to see if totalScore
is not equal to 10. Then you have to assign the resulting boolean value to the constant isWinner
like so:
// Enter your code below
var initialScore = 8
let totalScore = ++initialScore
let isWinner = totalScore != 10
I hope that helps! :)
Martin Wildfeuer
Courses Plus Student 11,071 PointsMartin Wildfeuer
Courses Plus Student 11,071 PointsQuick note:
++
and--
(pre- and post version) are deprecated as of Swift 2.2 and will be removed in Swift 3. They still work but they will trigger a compiler warning. You can find the link to the proposal here. Just mentioning this, as this might be confusing for Playground users :)Tobias Helmrich
31,603 PointsTobias Helmrich
31,603 PointsYup, thanks for mentioning it! :)
I just wanted to keep the code Sonu posted the same so I don't cause more confusion and the challenge description also explicitly mentions using the unary increment operator.
Martin Wildfeuer
Courses Plus Student 11,071 PointsMartin Wildfeuer
Courses Plus Student 11,071 PointsSure, absolutely! I just thought I'd mention it, the compiler warnings are causing a lot of confusion these days ;)