{ Coding for Kids }

Learn JavaScript

Build the
Room Adventure Game

Coding for Kids

The best way to learn to code is to build toward a goal. { Coding for Kids } is designed to get you there. This site hosts all the code for easy reference. To understand and learn about the code, you can purchase a copy of the book here.

Coding for Kids

The goal of the game

Our goal in this book is to make a video game that lets you go from room to room in a house, finding and picking up items, and using them to fix things that are broken.

This starts off as a text adventure, and when you're ready, we adapt it for HTML to add colors, buttons, and images.

The game can even be adapted for other settings. Want to make a fantasy-themed game? A space station? A village? You can, and easily.

Looking for the code files?

Check out the navigation bar for the pages you need.

What's on this site?

The main site contains tutorials for many aspects of JavaScript. It's a detailed reference guide with examples to look at.

The code for The Room Adventure is also here. If you're stuck getting your code to work, you can check the code here to see what's up.

What you'll learn

We cover a lot of ground in the book that will help you build the basics you need to create your own programs.

Note: The Room Adventure was written in JavaScript ECMAScript 5. The only difference that matters from the newer version, ECMAScript 6, is our use of the var keyword instead of the newer let keyword. For our purposes, there is no functional difference between the two.

Punctuation and Syntax

  • Learn about camelCase and why we need it.
    • It's like using hashtags, but a little different.
  • Understand the uses of whitespace and formatting your code.
    • Set up an outline so things are easier to read.
  • Learn how to add helpful comments to your code.
    • Leave messages for your future self.
  • Learn why we use different brackets in different situations.
    • From square brackets [] to round brackets ()
      to braces {} to quotation marks '' and "".
Coding for Kids Leena
Coding for Kids Sergei

Variables

  • Learn how to declare (create) your own variables.
    • We talk a little about local and global variables.
  • Learn the difference between variable types.
    • Strings (words), numbers, and true/false flags behave differently
  • Use variable values to give dynamic feedback
    • Telling a player what room they're in.
  • Change variable values with mathematical operators
    • Increasing the player's score.

Objects

  • Organize variables into objects
    • Have separate sets of details for each room.
  • Use object properties to access the information you need.
    • Get the description for the living room, not the dining room.
  • Use array notation for objects to access their properties.
    • Use variables to access those properties.
Coding for Kids Reiko
Coding for Kids Nathan

Arrays

  • Learn how to create an array.
    • Make an inventory bag for your player to carry things.
  • Learn how to access array elements using index numbers.
    • Such as needing to know the first thing that's on the list.
  • Learn how to add to and remove from an existing array.
    • When you find or use an item from the inventory.

Functions

  • Create your first function by simply wrapping your existing code.
    • It's a form of refactoring your code.
  • Learn to call functions when you need them.
    • When you're ready to pick up an item in a room.
  • Learn to create new functions from scratch.
    • Display the score on the screen.
  • Learn to send values back from a function and use them.
    • Move in the direction the player wants to go.
Coding for Kids Dr. Lupino
Coding for Kids Leena

Conditionals

  • Teach your program to make decisions.
    • Is it okay for the player to go west?
  • Learn to develop conditional if checks in your code.
    • Figure out whether or not a player won the game.
  • Learn when to use an else block.
    • If the player doesn't win the game that round, what happens next?
  • Learn how to use nested if/else statements.
    • When you need to check for several things.

Loops

  • Learn why loops are so important to programming.
    • What good is a game that stops after a single command?
  • Learn the difference between while and for loops.
    • What situation best fits each one?
  • Learn how to loop through the elements of an array.
    • Like when you want to display inventory items, you can format each one.
  • Learn how to loop through object properties.
    • Such as when you need all a room's exits but not its description.
Coding for Kids Sergei
Coding for Kids Reiko

JavaScript's Math Object

  • Learn to call for random numbers.
    • Randomize points values.
  • Learn to randomly select an element from an array.
    • Pull randomly from a list of clues.
  • Learn to use max and min to control the numbers you need.
    • Control how many exits the house has.

HTML Basics

  • Learn how to create the files you need to make a webpage.
    • Make your game into a clickable adventure instead of text-based.
  • Learn how to plan a user interface and create it with a table.
    • Decide where the buttons should go.
  • Learn how to add images to the game.
    • Add photos of each room.
  • Learn a method for making a dynamic set of buttons.
    • Have buttons only when you need them and getting rid of the ones you don't.
Coding for Kids Dr. Lupino
Coding for Kids Nathan

CSS Basics

  • Learn some basic formatting for your HTML.
    • Choose the fonts and colors.
  • Learn how to add borders or add background colors.
    • Design your own color scheme.
  • Learn a little about attribute inheritance.
    • When settings are passed along and how to override them.

Make every day an adventure!

—Dr. Wolf