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 2.0 Basics Swift Operators Working With Operators: Part 2

I can get past the first question even though I think I understand the process.

I am supposed to add a point, but it won't validate it. What am I doing wrong here?

operators2.swift
// Enter your code below

var initialScore = 8
initialScore = initialScore + 1

var totalScore = initialScore
totalScore = initialScore++

2 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,858 Points

Hey Thomas,

You've kind of over-complicated this a bit.

The first part of the challenge just wants you to assign the new value of initialScore to the constant totalScore. You are using ++ which is correct, except in this case that needs to be placed before the variable name.

When you place it after the variable, Swift will assign the value to the new variable and then increment the old. But, the challenge specifically says to have both equal the same. So, it needs to be placed before. This way, Swift will increment the variable before assigning it to the new variable.

So, all you need for Task 1 is:

let totalScore = ++initialScore

Also, a note. The ++ operator is deprecated in Xcode 7.3. Just an FYI.

:dizzy:

Create the constant totalScore (you must use let to create constants). Then increment initialScore and assign the result to totalScore:

var initialScore = 8

let totalScore = ++initialScore

Note that ++intialScore and initialScore++ have different results.

Thanks jcorum, I literally just found out that they where asking for a constant before you answered. Sorry for the inconvenience. I'll go make a cup of coffee :P