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

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

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

1 Answer

Rogier Nitschelm
seal-mask
.a{fill-rule:evenodd;}techdegree
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?

Example:

var totalScore = 0

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

let  isWinner = totalScore == 10 // true