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 trialKarthikeya Nadendla
9,747 PointsI dont understand the question
In this game of ours, we have an odd scoring mechanism . At the end of the round, if your score is 10, you lose! If it's anything but 10, you win.
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. (Hint: Use the NOT operator)
Please help me with the code, I dont even understand the question coz its easier to use if operator in such a case but how do we assign the results of a comparision operator to check ?
// Enter your code below
var initialScore = 8
let totalScore = ++initialScore
let lose = 10
let win = !10
let isWinner = totalScore
8 Answers
Jhoan Arango
14,575 PointsHello :
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. (Hint: Use the NOT operator)
So the challenge is asking you to declare a constant named isWinner and assign the results of a comparison operation.
Therefore, you want to do an operation where it compares something, and then that value is giving to the constant we want to declare.
Here is what you want to do:
var initialScore = 8
let totalScore = ++initialScore
// Here we are saying, if totalScore is not 10, then is winner.
let isWinner = totalScore != 10
Hopefully this helps you move on with your challenge.
Good luck.
Juno Jo
4,981 Pointsvar initialScore = 8
initialScore += 1
var totalScore = 10
let isWinner: Bool = totalScore >= initialScore
Charles Yoon
2,198 Pointsthis isn't working for me help lol
Jatinder Singh Saini
iOS Development Techdegree Student 1,317 PointsCharles Yoon you should write the code exactly let isWinner = totalScore != 10 (totalScore!=10) will not work, that is if you are not giving the space between totalScore and != operator it will not work ,so always take care of theses things while using operators.
Juno Jo
4,981 Pointsvar initialScore = 8 initialScore += 1 var totalScore = 10
let isWinner: Bool = totalScore >= initialScore
ttaleg
9,830 Pointssorry none of the code above works in mine
Andrew Merrick
20,151 PointsMy main complaint is that the directions do not indicate to create a variable/constant called "totalScore". This is should be included with the instructions. Also, "++" is not mentioned in any of the notes or videos up to this point so why are people using it?
Jhoan Arango
14,575 PointsHello Andrew:
If you notice this is an old question, and I think this was back when Swift 2.0 was still around. The "++" has been removed from the language in Swift 3, so it's no longer being used, at least for swift.
Sometimes the challenges do not give you all the necessary steps because it will stop being a challenge and it will be more of an instruction. Sometimes it's good to think outside the box and do some google research and see what kind of code you are able to create. This implementation can have other ways of being done, so that's why they do not give you all the details, they want you to solve it on your own and with your own style.
Good luck
Fernando Angulo
1,921 PointsHello Andrew!
Swift change ++ in the Unary Operators and It was replace with += since last year I think.
Andrew Merrick
20,151 PointsThanks!
Fernando Angulo
1,921 Points/*Challenge Task 1 of 2
In the editor, initialScore represents a user's score in a game. A user managed to beat the current level so first, let's add 1 point to their initial score using the unary plus operator. */
// Enter your code below var initialScore = 8 initialScore += 1
/*Challenge Task 2 of 2
In this game of ours, we have an odd scoring mechanism . At the end of the round, if your score is 10, you lose! If it's anything but 10, you win.
Declare a constant named isWinner and assign the results of a comparison operation to check whether the player has won or not. For example, if the total score is not 10, then the player has won and isWinner should equal true. (Hint: Use the NOT operator) */
// Enter your code below let isWinner = (initialScore != 10)
Karthikeya Nadendla
9,747 PointsKarthikeya Nadendla
9,747 PointsIts simple and straight forward, thank you so much
stephenallison
8,559 Pointsstephenallison
8,559 PointsJhoan, thanks for the explanation. The questions to me are very confusing just because I get lost in the actual verbiage. Hopefully with more practice i will be come more familiar with Swift terminology.