Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Swift Basics Swift Operators Working With Operators: Part 2

need help..

This my code and it keep saying I have an error

var initialScore = 8 let totalScore = ++initialScore let isWinner = 10 != 10 let isWinner = totalScore != 10

// Enter your code below
var initialScore = 8
let totalScore = ++initialScore
let  isWinner = 10 != 10 
let isWinner = totalScore != 10

1 Answer

Rogier Nitschelm
Rogier Nitschelm
iOS Development Techdegree Student 5,461 Points

I do not know the context of the assignment and if you have been exposed to loops and functions yet, but here are some things to help:

  • the initialScore should probably be the same value (0) in every case. If so, it might be a good idea to change the var into a let here.

  • if the totalScore is calculated more than once, you will have to change it from a constant to a variable. As the value stored is in that case subject to change. You could also consider dropping initialScore and just using 'var totalScore' to store the score at all times and set it to 0 initially.

  • let isWinner = 10 != 10 always results in false because 10 is equal to 10. Perhaps you want to compare the totalScore with the value 10?


var totalScore = 0

 // some logics that adds points to the score like
totalScore += 10

let  isWinner = totalScore == 10 // true