JavaScript is the brains behind the internet, updating websites, running games, and so much more. This book teaches you the basics of coding in JavaScript by creating The Room Adventure.
The game starts as a text-based adventure, going from room to room in a house you create. You find items and use them to fix broken things in other rooms.
Once the game structure is set, you can convert your game into HTML, adding colors, images, and you can travel through your house using buttons instead of typing!
You can easily share your creations with friends and family!
The focus of the book is to teach you standard coding concepts that stretch to any programming language. So even if you switch to another language later, the lessons you learn in this book will benefit you.
We talk about proper syntax for JavaScript, variable types, computer decision-making, loops, functions, and so much more.
In order to code, you only need simple text files. To test your code, you need access to an internet browser, but you don't need internet access. Chapter 1 covers the setup you need to get started.
This book is written by a middle school science teacher with over 21 years of experience working with teens. The format of the book is a step-by-step guide through the process with repetition and contains all the code available in the back of the book. A short reference guide is also included, as well as additional add-on features for the game on an exclusive website.
Here’s one of my rooms:
var name = "living room";
var points = 25;
var brokenThing = "fireplace screen";
var description = "A cozy room with a fireplace.";
var fixWith = "new wire";
var itemFound = "batteries";
var north = "dining room";
var south = null;
var east = "hallway";
var west = null;
Look carefully at the formatting.
This is how you need to declare your variables. These are all initialized with a value. It’s usually a good idea to give a variable a value right away, even if it’s null. However, you can also declare a variable like this: var someVariable; This sets memory aside for the variable but it’s not defined in any way. Go ahead and try it in your console like the others. It will say it’s undefined.
Were you able to get all of your variables to work? If not, you need to go back and try to figure out why. It’s really important. Make sure you’re not using “smart quotes.” Keep them "straight."
At this point, you’ve created a bunch of variables and displayed their values in the console window. You’ve successfully written some code!
May 12, 2018