Skip to main content Link Menu Expand (external link) Document Search Copy Copied

Chapter: Commands

The tasks in this chapter were no problem for my daughter. I think that other children of a similar age also understand very quickly how things work. In the end, it even turned out that she didn’t find the long sequences of commands very exciting see task #7.

On the other hand, I have to say that I personally found this approach to be a good one. I think when you realize yourself that you could optimize things, it’s time to learn new techniques.

Also, in each lesson, the newbie first gets to know the environment. Besides collecting gems, tasks like toggling switches or using a teleporter also come into play.

Our verdict

Thus, this chapter represents the absolute must-read for everyone.

Since we believe that our solutions are simple, we do not provide additional explanations of the source code here.

1. Issuing Commands

challenge-issuing-commands

Challenge solution code: Issuing Commands

1
2
3
4
5
6
// MIT License (MIT) Copyright (c) 2021 Rosi Regner
// Challenge: Issuing Commands
moveForward()
moveForward()
moveForward()
collectGem()

2. Adding a New Command

challenge-adding-new-command

Challenge solution code: Adding a New Command

1
2
3
4
5
6
7
8
// MIT License (MIT) Copyright (c) 2021 Rosi Regner
// Challenge: Adding a New Command
moveForward()
moveForward()
turnLeft()
moveForward()
moveForward()
collectGem()

3. Toggling a Switch

challenge-toggling-switch

Challenge solution code: Toggling a Switch

1
2
3
4
5
6
7
8
9
10
11
// MIT License (MIT) Copyright (c) 2021 Rosi Regner
// Challenge: Toggling a Switch
moveForward()
moveForward()
turnLeft()
moveForward()
collectGem()
moveForward()
turnLeft()
moveForward()
moveForward()

4. Portal Practice

challenge-portal-practice

Challenge solution code: Portal Practice

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// MIT License (MIT) Copyright (c) 2021 Rosi Regner
// Challenge: Portal Practice
moveForward()
moveForward()
moveForward()
turnLeft()
moveForward()
moveForward()
toggleSwitch()
moveForward()
moveForward()
turnLeft()
moveForward()
moveForward()
collectGem()

5. Finding and Fixing Bugs

challenge-finding-fixing-bugs

Challenge solution code: Finding and Fixing Bugs

1
2
3
4
5
6
7
8
9
10
11
12
// MIT License (MIT) Copyright (c) 2021 Rosi Regner
// Challenge: Finding and Fixing Bugs
moveForward()
moveForward()
turnLeft()
moveForward()
moveForward()
toggleSwitch()
turnLeft()
turnLeft()
moveForward()
collectGem()

6. Bug Squash Practice

challenge-bug-squash-practice

Challenge solution code: Bug Squash Practice

1
2
3
4
5
6
7
8
9
10
11
12
// MIT License (MIT) Copyright (c) 2021 Rosi Regner
// Challenge: Bug Squasch Practice
moveForward()
turnLeft()
moveForward()
moveForward()
toggleSwitch()
moveForward()
moveForward()
moveForward()
moveForward()
collectGem()

7. The Shortest Route

challenge-shortest-route

Challenge solution code: The Shortest Route

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// MIT License (MIT) Copyright (c) 2021 Rosi Regner
// Challenge: The Shortest Route
moveForward()
moveForward()
moveForward()
moveForward()
moveForward()
moveForward()
moveForward()
toggleSwitch()
moveForward()
moveForward()
turnLeft()
turnLeft()
turnLeft()
moveForward()
moveForward()
moveForward()
moveForward()
moveForward()
collectGem()

Read next: Learn to Code 1 - Chapter Functions