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

walter fernandez
walter fernandez
4,992 Points

In this game of ours, we have an odd scoring mechanism . At the end of the round, if your score is 10, you lose! If it's

help.

operators.swift
// Enter your code below

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

9 Answers

David Lin
David Lin
35,864 Points

You almost got it ...

  1. You misspelled "isWinner"
  2. isWinner needs to be set equal to the conditional initialScore != 10, because the conditional is what will be true or false.
// Enter your code below

var initialScore = 8
initialScore += 1

let isWinner = initialScore != 10
Juno Jo
Juno Jo
4,981 Points

var initialScore = 8 initialScore += 1 var totalScore = 10

let isWinner: Bool = totalScore >= initialScore

Juno Jo
Juno Jo
4,981 Points
var initialScore = 8
initialScore += 1
var totalScore = 10

let isWinner: Bool = totalScore >= initialScore
walter fernandez
walter fernandez
4,992 Points

i have i question, because when i want to make a conversation like var karina = "Hi pedro, i need you today" var pedro = "Hi karina, yer tell me" karina var pedro = "are you joking?" i cannot because it says that i type pedro already how can i fix that?

David Lin
David Lin
35,864 Points

Walter, don't re-declare w/ var again, just re-assign pedro directly:

var karina = "Hi pedro, i need you today" 
var pedro = "Hi karina, yer tell me"
pedro = "are you joking?"
walter fernandez
walter fernandez
4,992 Points

thanks man, you are the best.

David Lin
David Lin
35,864 Points

you're welcome! :-)

walter fernandez
walter fernandez
4,992 Points

hello again i do not want to bother you but i try to tell karina that she is dumb and I ( pedro) will give a exercise to prove that but when i type pedro = 123 % 2 or var pedro = 123 % 2 or let pedro = 123 % 2 it appears like error could you help me?

walter fernandez
walter fernandez
4,992 Points

hi i did that pedro = "are you joking?" karina = "i am not stupid" pedro = "yes you are, and also you do not know anything of math" pedro = "how much is 123 % 12 ? " karina = i want to know how karina can say that answer because if i type karina = 123 % 12 it appears like a error.

David Lin
David Lin
35,864 Points

That's because your variables were already inferred to be of string type. So any new value you later assign to them must also be string.

For example, try:

katrina = "\(123 % 12)"

or

let answer = 123 % 12

katrina = "That's easy! The answer is \(answer)."

Wrapping a non-string value inside \() to make it a string is called string interpolation.

walter fernandez
walter fernandez
4,992 Points

My friend, if i want karina to say a wrong answer how can i do that if i already named her for example var karina = " hi" var pedro = "hello" // if i type karina == pedro // I know that it is going to be false, but after that i type pedro = "give me the answer" pedro = 2 + 2 // i want karina to reply wrongly and that it appears in my code as false.

David Lin
David Lin
35,864 Points

hey Walter - sorry, I don't understand your question. For one thing, you wouldn't be able to assign pedro to both a string ("give me the answer") and an int (2+2) with the same var declaration. I didn't understand the rest of what you're trying to do.