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 trialZach Plotkin
128 PointsI'm not sure what is wrong with this code and why it won't get accepted.
Thanks for the help, Zach
// Enter your code below
var initialScore = 8
initialScore = ++initialScore
let totalScore = initialScore
2 Answers
Greg Kaleka
39,021 PointsHi 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.
var initialScore = 8
let totalScore = ++initialScore
Make sense?
Cindy Lea
Courses Plus Student 6,497 PointsIs totalScore declared? I see initialScore is.
Zach Plotkin
128 PointsI 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
Courses Plus Student 6,497 PointsNever mind. I just read let is for constants and var is for variables.
Greg Kaleka
39,021 PointsGreg Kaleka
39,021 PointsP.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.