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

hello can someone help me please

i did my best

operators.swift
// Enter your code below

var initialScore = 8
initialScore += 1
let isWinner = true
isWinner = !10

2 Answers

Hey,

1) At glance you should see that the last two lines will never work. Why? Well, "isWinner" is a constant. And what you can't do with a constant (but can with a variable)? :) 2) Your intention is fine, however, it's not finished. By "!10" you say it's not 10. But what it's not 10? Yes, you want to know whether initialScore is equal to 10 or not 3) EXTRA: Another solution (without not operator) is by using "<" operator :)

Stanley Miller
Stanley Miller
2,910 Points

One solution is:

var initialScore = 8
initialScore += 1
let isWinner: Bool
if initialScore != 10 { isWinner = true } else { isWinner = false }

In order to mutate isWinner, you can't assign a value instead just assign a type. Then add an if/else statement to determine wether initialScore is equal to 10 or not. Hope that helps.