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 trialBrian Patterson
19,588 PointsNot sure why this is wrong
Not sure why this code is wrong in the challenge
var initialScore = 8
let totalScore = ++initialScore
var isWinner = 10
isWinner != ++totalScore
3 Answers
Amal Abualrahi
Courses Plus Student 3,905 PointsIn this lesson, no conditional if statement was introduced.
What you had have done here is that you have written:
isWinner != ++totalScore
which is wrong. You want to compare if the value of totalScore equal to 10 or not, and assign the result to another var called isWinner. so you will use != just like what you did to compare totalScore with 10 not with ++totalScore. I'm not sure why did you use the increment operator here, or why did you assign 10 to the isWinner variable !
here is the right answer:
var initialScore = 8
let totalScore = ++initialScore
var isWinner = totalScore != 10
Farhad Mohammad Afzali
5,007 PointsHello, You are not using any conditional statement there. Here is my solution:
var initialScore = 8
let totalScore = ++initialScore
var isWinner = false
if totalScore != 10 { isWinner = true } else { isWinner = false }
Hope it helps
Brian Patterson
19,588 PointsThanks for that.
Stephaughn Alston
463 PointsStephaughn Alston
463 PointsI'm confused on how this is the right answer. In the directions he said "create a constant", so 'isWinner' should've started with 'let' correct?
Amal Abualrahi
Courses Plus Student 3,905 PointsAmal Abualrahi
Courses Plus Student 3,905 Points@StephaughnAlston at that time I was not looking at the question page itself. I just corrected what was wrong with the code flow here. Hence I'm not sure if it was constant or variable there.
Maybe people marked it as a correct answer for the explaination of the main issue here? Because it was not about var vs constant
I will check the Q later on when I have time and update my answer. Thank you for the notice
Have a nice weekend