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

what's wrong?

what's wrong?

operators2.swift
// Enter your code below

var initialScore = 8
initialScore++
let totalScore = initialScore

2 Answers

Try putting the "++" part before the initialScore. Take a look here:

// Enter your code below

var initialScore = 8
// See how I put the ++ before initialScore? This should fix it :)
++initialScore
let totalScore = initialScore

Hope this helps! ~Alex

David Lin
David Lin
35,864 Points

Alex,

Just a note, the way he had it should've given the correct result, because the increment will occur regardless if you put the ++ before or after initialScore by the time it's assigned to totalScore since the incrementing is on a separate line.

What you said will make a difference if he put it in one line, like:

let totalScore = initalScore++ \\ <-- this won't increment initialScore before assigning to totalScore

I think it's just a bug in the coding algorithm that's not accepting his original answer, because by the time he assigns totalScore to initialScore, it is already incremented, which should be correct.

David Lin
David Lin
35,864 Points

Technically, your answer is correct, but I think their answer-checking algorithm is looking for something very specific. For example, the following passes:

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

Nice catch! I knew you could do that, it's just I like to keep code nice and simple so new programmers wouldn't get frustrated not understanding what's going on.

~Alex