Guessing.swift Project in Swift Course

Ok, so this is not making sense to me. The lesson text is telling me to reassign guess and magicNum to Int.random(in: 1...10). Aren’t they already assigned to that?

When I click the ’ Stuck? Need a hint?’ it does not offer any helpful info…

var guess = Int.random(in: 1...10)
var magicNum = Int.random(in: 1...10)

// Add your code here ✨
while guess != magicNum {


print("You're right it was \(guess)!") 

Hello! Could you post a link to this exercise, please?

Hi @codeneutrino. Sure thing, here is the link :slight_smile:


You have to reassign them inside the while loop as well.

If your program runs and guess comes out to be the same as magicNum, then it will skip the while loop and continue on. Otherwise, it will enter the while loop.

If you don’t assign guess and magicNum to different random numbers inside the loop, then your program will be stuck in an infinite loop –
guess != magicNum will always be true and your program will never exit the while block.

1 Like

Thank you, @el_cocodrilo! I see… OK so this lesson was frustrating because that was never discussed before and the example given in the lesson is a different setup than required in the practical. BUT, I get it! It’s actually quite a simple ’ answer.’ :man_facepalming:

Thank you!! :clap:

1 Like