Stumbled on an educational Blockly/javascript code maze game based on the Google’s Blockly library.

Google Blockly

Google Blockly

Tweet Image

Google’s Blockly library is used for coding apps like Scratch and ScratchJr.

Google’s Blockly Games Maze

Google’s Blockly Games Maze section has 10 mazes which introduce the concept of programming loops and conditions in javascript without writing any javascript code.

Blockly Games maze starts with really simple mazes, but a few of the later levels are challenging: I got stuck on maze 10 for a while.

Google’s Blockly Games Maze 1 Solution

Google Blockly Games Maze 1 Solution

Google Blockly Games Maze 1 Solution

Tweet Image

Google Blockly Games Maze 1 Solution

Congratulations!

You solved this level with 2 lines of JavaScript:

moveForward();
moveForward();

Are you ready for level 2?

Google’s Blockly Games Maze 2 Solution

Google Blockly Games Maze 2 Solution

Google Blockly Games Maze 2 Solution

Tweet Image

Google Blockly Games Maze 2 Solution

Congratulations!

You solved this level with 5 lines of JavaScript:

moveForward();
turnLeft();
moveForward();
turnRight();
moveForward();

Are you ready for level 3?

Google’s Blockly Games Maze 3 Solution

Google Blockly Games Maze 3 Solution

Google Blockly Games Maze 3 Solution

Tweet Image

Google Blockly Games Maze 3 Solution

Congratulations!

You solved this level with 3 lines of JavaScript:

while (notDone()) {
  moveForward();
}

Are you ready for level 4?

Google’s Blockly Games Maze 4 Solution

Google Blockly Games Maze 4 Solution

Google Blockly Games Maze 4 Solution

Tweet Image

Google Blockly Games Maze 4 Solution

Congratulations!

You solved this level with 6 lines of JavaScript:

while (notDone()) {
  moveForward();
  turnLeft();
  moveForward();
  turnRight();
}

Are you ready for level 5?

Google’s Blockly Games Maze 5 Solution

Google Blockly Games Maze 5 Solution

Google Blockly Games Maze 5 Solution

Tweet Image

Google Blockly Games Maze 5 Solution

Congratulations!

You solved this level with 6 lines of JavaScript:

moveForward();
moveForward();
turnLeft();
while (notDone()) {
  moveForward();
}

Are you ready for level 6?

Google’s Blockly Games Maze 6 Solution

Google Blockly Games Maze 6 Solution

Google Blockly Games Maze 6 Solution

Tweet Image

Google Blockly Games Maze 6 Solution

Congratulations!

You solved this level with 6 lines of JavaScript:

while (notDone()) {
  if (isPathLeft()) {
    turnLeft();
  }
  moveForward();
}

Are you ready for level 7?

Google’s Blockly Games Maze 7 Solution

Google Blockly Games Maze 7 Solution

Google Blockly Games Maze 7 Solution

Tweet Image

Google Blockly Games Maze 7 Solution

Congratulations!

You solved this level with 6 lines of JavaScript:

while (notDone()) {
  if (isPathRight()) {
    turnRight();
  }
  moveForward();
}

Are you ready for level 8?

Google’s Blockly Games Maze 8 Solution

Google Blockly Games Maze 8 Solution

Google Blockly Games Maze 8 Solution

Tweet Image

Google Blockly Games Maze 8 Solution

Congratulations!

You solved this level with 9 lines of JavaScript:

while (notDone()) {
  if (isPathLeft()) {
    turnLeft();
  }
  if (isPathRight()) {
    turnRight();
  }
  moveForward();
}

Are you ready for level 9?

Google’s Blockly Games Maze 9 Solution

Google Blockly Games Maze 9 Solution

Google Blockly Games Maze 9 Solution

Tweet Image

Google Blockly Games Maze 9 Solution

Congratulations!

You solved this level with 10 lines of JavaScript:

while (notDone()) {
  if (isPathForward()) {
    moveForward();
  } else {
    if (isPathLeft()) {
      turnLeft();
    }
    moveForward();
  }
}

Are you ready for level 10?

Google’s Blockly Games Maze 10 Solution

Google Blockly Games Maze 10 Solution

Google Blockly Games Maze 10 Solution

Tweet Image

Google Blockly Games Maze 10 Solution

Congratulations!

You solved this level with 18 lines of JavaScript:

while (notDone()) {
  moveForward();
  if (isPathForward()) {
    if (isPathRight()) {
      turnRight();
    } else {
      if (isPathLeft()) {
        turnLeft();
      }
    }
  } else {
    if (isPathLeft()) {
      turnLeft();
    } else {
      turnRight();
    }
  }
}

Are you ready for the next challenge?

Google’s Blockly Games Maze 10 Best Answer Video

The previous level 10 solution is quite complicated and doesn’t use the tip to follow the left wall. The answer in the video above follows the left wall, uses fewer lines of code and is far more elegant (the best answer).

Google Blockly Games Maze 10 Best Answer

Google Blockly Games Maze 10 Best Answer

Tweet Image

Google Blockly Games Maze 10 Solution

Congratulations!

You solved this level with 10 lines of JavaScript:

while (notDone()) {
  if (isPathLeft()) {
    turnLeft();
  }
  if (isPathForward()) {
    moveForward();
  } else {
    turnRight();
  }
}

Are you ready for the next challenge?

David Law