King or Coral explainer

The aim of this puzzle: Remove the bottom stripes from the snake until there are no red and yellow boxes touching.
Walkthrough of the solution: The for loop is just used to see the snake, so that part doesn’t need to be changed. When you run the code you’ll see that there are red and yellow boxes next to each other at the end. If you take 3 stripes off of the bottom, there will be no red and yellow boxes touching. Since the boxes are drawn from the colors listed in the pattern array, the last item in the array corresponds to the bottom of the snake. The .pop() command removes the last item from an array, so pattern.pop() does exactly what you want. However, it will only take one item at a time, so you will have to use pattern.pop() several times in a row. You have to place the commands before you draw the snake which means they should be above the for loop in your code.

Another cool thing about .pop() is that it’s not really deleting the last item in the array – it detaches it so you can send it somewhere else, like to a variable or directly into a drawBox(). That means if you kept using drawBox(pattern.pop()) you could draw the snake backwards!

Sample code solution:
(Tap below to reveal)

pattern.pop();
pattern.pop();
pattern.pop();
for (var element of pattern) {
  drawBox(element);
  newLine();
}

JavaScript Concepts: Code Block (for loop), Calling Functions, Identifiers
Grasshopper Concepts: drawBox(), newLine()