Post

Replies

Boosts

Views

Activity

Swift Playground not accepting my solution
I have reached to Learn to Code 2, Chapter: Types, Corner of The World puzzle. however; I have provided a solution and the Playground did not close the puzzle, but the avatar stop moving as it meets the conditions I set!! I searched the internet and found the solution, I copied the solution, the puzzle closed!! but my solution was much shorter than the solution!! I am not sure what is wrong in my code, I have attached my code. `greenPortal.isActive = false orangePortal.isActive = false var numberOfGems = 0 var numberOfSwitchs = 0 func moveAround() {     if isBlockedRight {moveForward()} else {turnRight()         moveForward()              }     if isBlocked {turnLeft()         turnLeft()     } } turnRight() moveForward() for steps in 1...2 {     moveForward()     turnRight()     moveForward()     if isOnClosedSwitch {toggleSwitch(); numberOfSwitchs = numberOfSwitchs + 1}     turnLeft()     turnLeft() } while !isBlocked {     while numberOfSwitchs < 6 {         moveAround()         if isOnGem {collectGem(); numberOfGems = numberOfGems + 1}         if numberOfGems == 6 {greenPortal.isActive = true}         if isOnClosedSwitch {toggleSwitch(); numberOfSwitchs = numberOfSwitchs + 1}         if isOnOpenSwitch {greenPortal.isActive = false}     } }
1
0
1.2k
May ’22