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 trial
Natalia Rialucky
868 PointsNeed help with a challenge
Im on the unary challenge, been stuck for a day: Do you know how to assign isWin to the result of the comparison that totalScore is not 10 (totalScore is not parameter)?
var initialScore = 8
let totalScore = ++initialScore
initialScore = totalScore
let parameter = 10
totalScore = !parameter
let isWin = ??
Thanks
4 Answers
Steve Hunter
57,712 PointsFound it!
Right - so we start with initialScore = 8 in the editor and the question is add 1 point to their score using the increment operator and assign the result to a constant named totalScore.
For that we use the increment operator, ++. We need to make sure that the value we assign into totalScore is the same as that found in initialScore after the increment. So, that means we use the operator before the variable:
var initialScore = 8
let finalScore = ++initialScore
You've got that far - all good. Next up Declare a constant named isWinner and assign the results of a comparison operation to check whether the player has won or not. If the total score is not 10, then the player has won, otherwise he or she has lost.
So, if the value of totalScore is 10 then isWinner should be false as the player didn't win. If the value isn't 10, the isWinner should be true as the player did win. Sounds like an odd game to me, but that's what we've got!
We want to ask if totalScore is not equal to 10. Store the result of that in isWinner:
let isWinner = totalScore != 10
That should do it for you.
Steve.
Steve Hunter
57,712 PointsHi Natalia,
Can you post a link to the challenge, please? I can't find it.
Thanks,
Steve.
Natalia Rialucky
868 PointsThank you so much Steve! I didnt know I can put another = after the first =. Works, thanks!
Steve Hunter
57,712 PointsNo problem - glad it worked.
You can put another operator after the assignment = sign, yes. You can't put another = as a double assignment would cause issues. But you can assign the result of a comparison. So, if you wanted to know if two things were equal, and save that in a constant, you can put:
let isEqual = (oneThing == anotherThing)
I added the brackets to make it a little clearer. Here, we're using the comparison operator == which checks whether two things are the same. That evaulates to a true or a false, and that value is stored in isEqual.
Just the same as the challenge, but there we were checking that two things weren't equal:
let isNotEqual = (totalScore != 10)
We check the two 'things' just the same - one thing is the value stored in totalScore and the other thing is the value of 10. We compare if they're the same and assign the result back into isWinner.
Make sense?
Steve.
Natalia Rialucky
868 PointsI see.. it is possible because the second = function as an operator after the = assignment sign, and not double assignment.. Make sense. Thanks, very useful! (Hope you dont mind, I'll be reaching out quite often and save a day of figuring out)
Steve Hunter
57,712 PointsYeah - so problem at all - just mention me with an @ and I'll see it, Natalia Rialucky !