Sponsored

Collapse

Announcement

Collapse
No announcement yet.

Round Up the Switches - Swift Playgrounds

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Round Up the Switches - Swift Playgrounds

    The challenge of this level is to toggle the same number of switches on the second platform as the number of gems collected on the first platform.

    Use your knowledge of variables, assignment, and comparison operators to create a solution for this puzzle. Remember, it's okay if you don't get the solution on your first try! Trying different approaches allows you to to learn from your mistakes, giving you a deeper understanding of the code that you write.

    Click image for larger version

Name:	Screen Shot 2017-01-02 at 12.16.17 AM.png
Views:	1500
Size:	295.8 KB
ID:	1275

    Hint: On the first platform, a random number of gems will appear. Check each tile and increment a gem-counting variable to count the number you collect.

    The complete solution is shown below:

    Code:
    var gemCounter = 0
    var switchCounter = 0
    while switchCounter != gemCounter || switchCounter != 0 {
     moveForward()
     if isOnGem {
      collectGem()
      gemCounter = gemCounter + 1
     } else if isOnClosedSwitch {
      toggleSwitch()
      switchCounter = switchCounter + 1
     }
     if isBlocked {
      turnRight()
     }
    }
    Very impressive! You've solved some difficult puzzles involving variables. Nice work! Ready for the last challenge?

    The next lesson is collect the total.

  • #2
     

    Comment


    • #3
      ..........
      Last edited by Joe Mama; 10-24-2019, 01:12 PM.

      Comment


      • #4
        Hi, trying to step my way thru this... can anyone tell me WHY the guy is NOT moving forward with this bit of code? I think he should be. Click image for larger version

Name:	9A5A1F00-2B86-4680-8095-2693486EE545.png
Views:	160
Size:	808.8 KB
ID:	16500

        Comment

        Apple Swift Programming Language

        About this Group

        Discussion group for Swift programming language by apple for Xcode
        Type: Public
        Topics: 112
        Comments: 85

        Owner

        Sponsored Box

        Collapse

        Latest Group Topics

        Collapse

        There are no results that meet this criteria.

        Working...
        X