I’m really stuck on the 3 Gems, 4 Switches part of Learn To Code 2.
Why, in my code below, does the little man turn on four switches and stop (the correct behaviour) but wont stop collecting the gems at 3, and instead just collects them all?
Would love a pointer.
Why, in my code below, does the little man turn on four switches and stop (the correct behaviour) but wont stop collecting the gems at 3, and instead just collects them all?
Would love a pointer.
Swift:
var gemCounter = 0
var switchCounter = 0
func gemGem() {
if isOnGem {
collectGem()
gemCounter = gemCounter + 1
}
}
func switchSwitch() {
if isOnClosedSwitch {
toggleSwitch()
switchCounter = switchCounter + 1
}
}
while gemCounter < 3 || switchCounter < 4{
moveForward()
gemGem()
switchSwitch()
if isBlocked && isBlockedLeft {
turnRight()
}
if isBlocked && isBlockedRight {
turnLeft()
}
}