Ask coding questions

← Back to all posts
what am I doing wrong?
joshuam6060 (0)

I am trying to do a "guess my number game"

else{
while z < number {
print( "too low")
}
}

Answered by Coder100 (8277) [earned 5 cycles]
View Answer
Commentshotnewtop
Coder100 (8277)

Like the other problem, you forgot to turn the string to int. Just copy and paste line 25:

  while Int(z ?? "0") < number {
    print("too low")
  }
Coder100 (8277)

@joshuam6060 oh oops typo:

while Int(z) ?? 0 < number {
Coder100 (8277)

oops that doesn't work either. This does:

  while (Int(z ?? "0") ?? 0 < number) {
    print("too low")
    z = readLine()
  }
  print("yay you got the number!")

@joshuam6060

PattanAhmed (1102)

@joshuam6060 Hi,
It is clear:-
binary operator '<' cannot be applied to operands of type 'String?' and 'Int'

  while z < number

That's it.
Thanks!

Hope this helps