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

yusuf Dibswazit
yusuf Dibswazit
1,522 Points

teamTreeHouse GET YOUR ACT OF ASKING QUESTIONS TOGETHER!!

Challenge Task 1 of 2

Let's assume we're creating a silly game. In this game every time a user completes an objective (whatever it is) we increment their total score by 1 point.

In the editor below, initialScore is the players current score. Assuming they completed a single objective for this level, let's add 1 point to their score using the increment operator and assign the result to a constant named totalScore.

Remember that the position of the unary increment operator matters. For this task to pass, we want both totalScore and initialScore to have the same value after the increment operation. Bummer! Make sure you're assigning the results of the increment operation to a constant named totalScore Preview Get Help Recheck work operators2.swift

1 // Enter your code below 2 ā€‹ 3 var initialScore = 8 4 // below is my code initialScore = initialScore +1 5 ā€‹ 6 var totalScore = initialScore 7 totalScore = ++initialScore


Hi, first of all, as someone who is starting out new, you would think that the questions would be directly related to what was taught in the previous lesson.

The question is so confusing and not structured properly enough for me, that i do not know where i'm going wrong. Having two parts in one question, there is NO WAY for me to know exactly which line is wrong and which isn't, or if all of the code is wrong.

would anyone be as so kind to tell me where my mistakes are, as i have watched and re-watched the previous lesson multiple times over.

P.S when i use to post a question, the code was automatically copied when i checked the box for "include code in the question". Now recently every time i would ask someone a question, they would tell me that i must include the code to make it more clear of what i'm asking. Now i have to copy/paste every time to include my code. Is there another easier way to this tedious task ?

1 Answer

Michael Reining
Michael Reining
10,101 Points

Hi there,

I understand your frustration. Getting started is hard. My tip is to try to solve every code challenge first in the Playground in Xcode. It gives you far better feedback / real time responses than the code check in Team Treehouse.

If you add the code below in the Playground, you will already see the results and see what happens.

var initialScore = 8

let totalScore = ++initialScore // returns 9
let isWinner = totalScore != 10 // returns true

Also, learn how the Markdown works when posting questions and it will be much easier for others to look at your code to offer suggestions of what went wrong.

I hope that helps,

Mike

PS: Thanks to the awesome resources on Team Treehouse, I just launched my first app. :-)

Code! Learn how to program with Swift

yusuf Dibswazit
yusuf Dibswazit
1,522 Points

hi, appreciate your response, but i'm afraid i did not understand. and this is where i always get lost with tree house's questions : The Last Part Of the Question Say's : ((Remember that the position of the unary increment operator matters. For this task to pass, we want both totalScore and initialScore to have the same value after the increment operation.))

In your last line of code, you came up with a constant called "let isWinner". How as someone who is new (like me), find out/associate those instructions given, to an answer like your's ( which works btw ).

Even furthermore, when applying your code to the Playground in Xcode, it gave me two errors. for your second line it gave : Invalid redeclaration of 'totalScore'. for the last line of code it gave: Unary operator cannot be separated from its operand.

So even when applying it to the playground Xcode, im getting no where, and when i copied and pasted your code to answer the question, it was a pass.

p.s good luck with your first app :)

UP DATE: as i have just gone into the second part, i can now see where "isWinner" has come from, but this just further proves my point that the questioner challange just accepts all the code i had just thrown at it for the 1st part. instead of telling me where im going wrong, or which code is ONLY needed for THAT particular part of the question.