Ask coding questions

← Back to all posts
error cannot assign value of type int to string swift - what am I doing wrong?
joshuam6060

print("guess a number that I thought of")
let number = Int.random(in: 0...100)
var z = readLine()
if z = number{
print("yay")
}

Answered by Coder100 [earned 5 cycles]
View Answer
Voters
joshuam6060
Comments
hotnewtop
Coder100

Right here, you forgot an =. Remember. = is for assignment and == is for equality:

joshuam6060

@Coder100
I tried that and it didn't work.

Coder100

z has to be of type string @joshuam6060

Coder100

@joshuam6060

joshuam6060

still isn't working @Coder100

Coder100

oh right, z can be optional.

@joshuam6060

joshuam6060

thanks you so much @Coder100

Coder100