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

Zach Plotkin
Zach Plotkin
128 Points

I'm not sure what is wrong with this code and why it won't get accepted.

Thanks for the help, Zach

operators2.swift
// Enter your code below

var initialScore = 8

initialScore = ++initialScore  

let totalScore = initialScore

2 Answers

Greg Kaleka
Greg Kaleka
39,021 Points

Hi Zach,

You're close! You'll actually end up in the same place, but the challenge wants you to do this in one step, not two as you've done.

skipAStep.swift
var initialScore = 8

let totalScore = ++initialScore

Make sense?

Greg Kaleka
Greg Kaleka
39,021 Points

P.S. Swift 3 is coming out soon, and the increment and decrement operators (++ and --) are going away. They add confusion without much benefit (adding + 1 instead only requires a couple extra spaces, and Swift no longer uses C-style loops that often use these operators).

Here's the accepted proposal.

Zach Plotkin
Zach Plotkin
128 Points

I just changed it to this:

// Enter your code below

var initialScore = 8 initialScore = initialScore + 1

var totalScore = initialScore + 8 totalScore = --initialScore

totalScore += 1

I'm not sure why this one is wrong. And what is declared mean again? Thanks!

Cindy Lea
Cindy Lea
Courses Plus Student 6,497 Points

Never mind. I just read let is for constants and var is for variables.