Skip to content
ExploreMapGamesStoriesComicsVideosStudioPrintablesCode LabJourneys
By age โ–พ
  • ๐Ÿงธ Tiny Explorers2โ€“5
  • ๐Ÿฆ‰ Curious Learners6โ€“8
  • ๐Ÿ”ญ Young Investigators9โ€“12
  • ๐Ÿš€ Trailblazers13โ€“17
๐Ÿ‘คParent sign in
Kids Amazing World

A creative learning playground. No ads, no tracking, no chat. Every item is reviewed before it appears.

Explore

  • Explore
  • Learning journeys
  • Surprise me
  • Parent planner

For grown-ups

  • Child safety
  • Privacy
  • Terms (draft)
  • Free & Premium
  • Parent sign in

About this content

Some items in this build are placeholders written for development. Third-party resources are only listed with permission, a license, or an official embed.

โ† All game tutorials

๐Ÿ Snake

Eat apples, grow longer, and don't crash!

How to playYour functionsSettings you can changeStep by stepIdeas to tryLessons

๐ŸŽฎ How to play

Reach the goal score by eating food, without running out of lives. Crashing into a wall or into your own tail costs a life, and the snake restarts.

  • Arrow keys or W A S D, or the four arrow buttons: Turn the snake. It can't turn back on itself.

โš™๏ธ Your functions

You write these functions. The game calls them when something happens.

  • onEat()

    Runs every time the snake eats food.

    function onEat() {
      score = score + 1;
    }
  • onCrash()

    Runs when the snake hits a wall (unless wrap is on) or its own body.

    function onCrash() {
      lives = lives - 1;
    }

๐ŸŽš๏ธ Settings you can change

Variables at the top of your code are the game's settings. Change a value, press Play, and see what happens.

head = "๐Ÿ"
The emoji for the snake's head.
snake = "๐ŸŸฉ"
The emoji for its body.
food = "๐ŸŽ"
The emoji it eats.
goal = 10
Reach this score to win.
lives = 3
Crashes you are allowed.
speed = 2
From 1 (slow) to 5 (fast).
wrap = false
true turns the walls into portals: leave one side and you come back on the other.
growth = 1
How many segments the snake grows when it eats (0 to 5).
score = 0
Your points. The game starts it at 0 and you change it in your functions. set by the game

๐Ÿชœ Step by step

Each step shows code you can add to the end of your game's code. A function or variable written later replaces the earlier one, so you never have to delete anything.

  1. 1Play the starter

    Steer the snake to the food. Each apple runs onEat, and each crash runs onCrash.

    function onEat() {
      score = score + 1;
    }
  2. 2Portal walls

    Set wrap to true and the snake can no longer crash into the walls: it appears on the opposite side.

    let wrap = true;
  3. 3Bigger apples

    Make every apple add 2 segments to the snake and 3 points to your score.

    let growth = 2;
    
    function onEat() {
      score = score + 3;
    }
  4. 4Speed up as you score

    Every time your score is a multiple of 3, the snake gets faster (never above 5). The % sign gives the remainder after dividing.

    function onEat() {
      score = score + 1;
      if (score % 3 === 0 && speed < 5) {
        speed = speed + 1;
      }
    }
  5. 5A crash that resets the pace

    A crash can change more than your lives. Here it costs a life and puts the speed back to 2.

    function onCrash() {
      lives = lives - 1;
      speed = 2;
    }
Show the full starter code
// ๐Ÿ Snake!
let head = "๐Ÿ";      // your snake's head
let snake = "๐ŸŸฉ";     // its body
let food = "๐ŸŽ";      // what it eats
let goal = 10;          // reach this score to win
let lives = 3;
let speed = 2;         // 1 (slow) to 5 (fast)
let wrap = false;       // true: leave one side and come back on the other
let growth = 1;       // how many segments one apple adds

function onEat() {
  score = score + 1;
}

function onCrash() {
  lives = lives - 1;
}

๐Ÿ’ก Ideas to try

  • A frog ๐Ÿธ that eats flies ๐Ÿชฐ.
  • Start at speed 1 and make the game faster with every apple.
  • Give 10 lives, but make each crash cost 5 points.
  • Turn wrap on only after you've eaten 5 apples.

Tips

  • Tap the board once so the keyboard controls work.
  • A big speed number is really hard! Try 3 first.

๐ŸŽ“ Lessons for this game

  • ๐Ÿ”’Snake: your first bitePremium
  • ๐Ÿ”’Snake: portal wallsPremium
  • ๐Ÿ”’Snake: speed demonPremium

๐Ÿ› ๏ธ Make your own Snake game

Game Studio and the full lessons are part of Premium.

See Premium
โ† โ“ Quiz Show๐Ÿงฑ Tetris โ†’