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 trialCaden Nichols
389 PointsI too could not figure out the final code challenge
Everyone that answered on Jonathan Boisvert's post who had the same question was incorrect.
We have this
var initialScore = 8 initialScore += 1
and we're supposed to declare a constant named isWinner to not equal 10
let isWinner = !10 does not work because "Cannot convert value of type 'Int' to expected argument type 'Bool'"
5 Answers
York Brady
1,053 PointsYou need to assign a boolean value to "isWinner". We use the comparison
initialScore != 10
to determine if the score is equal to 10 or not. Then, that boolean value gets assigned to isWinner like so:
let isWinner = initialScore != 10
The answer on the other post is correct.
Refath Bari
595 PointsAn alternative solution:
let initialScore = 0
iniitalScore += 1
let isWinner = !(initial Score = 10)
So, the final line will negate whatever initial Score = 10
is. If initial Score = 10
is true, then winner=false
. If initial Score = 10
is false, then winner=true
!
Michael Hulet
47,913 PointsThis isn't connected to any specific code challenge (instead, a video), so I can't really say whether or not this'll pass the challenge you're working on, but your code will not compile in Swift. Swift is different from its C-family predecessors in that it doesn't treat booleans as integers where 0
is false
and everything else is true
. A Swift Bool
is its own distinct type that can't be converted directly to an Int
and vice-versa using any operators, like the boolean inversion operator (!
). While writing something like !10
is perfectly valid in Objective-C, it doesn't work in Swift. Based on what you've pasted in from the question, I'm guessing that the challenge wants you to check if a variable *is not equal to 10
, which is a different operator. You can check if a value is not equal to another value with the not-equal comparison operator (!=
), like this:
let someValue = 8
let first = someValue != 20 // first is true
let second = someValue != 8 // second is false
Steven Parker
231,248 PointsHe seems to be working on this challenge.
Caden Nichols
389 Points^^^ Yes that challenge
Jaydev Sachdeva
423 Points// Enter your code below
var initialScore = 8 initialScore += 1
let isWinner = !(initialScore==10)