Coding For Kids For Dummies®, 2nd Edition
Published by: John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030-5774, www.wiley.com
Copyright © 2019 by John Wiley & Sons, Inc., Hoboken, New Jersey
Published simultaneously in Canada
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without the prior written permission of the Publisher. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permissions
.
Trademarks: Wiley, For Dummies, the Dummies Man logo, Dummies.com, Making Everything Easier, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and may not be used without written permission. All other trademarks are the property of their respective owners. John Wiley & Sons, Inc. is not associated with any product or vendor mentioned in this book.
LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR MAKE NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF THE CONTENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE. NO WARRANTY MAY BE CREATED OR EXTENDED BY SALES OR PROMOTIONAL MATERIALS. THE ADVICE AND STRATEGIES CONTAINED HEREIN MAY NOT BE SUITABLE FOR EVERY SITUATION. THIS WORK IS SOLD WITH THE UNDERSTANDING THAT THE PUBLISHER IS NOT ENGAGED IN RENDERING LEGAL, ACCOUNTING, OR OTHER PROFESSIONAL SERVICES. IF PROFESSIONAL ASSISTANCE IS REQUIRED, THE SERVICES OF A COMPETENT PROFESSIONAL PERSON SHOULD BE SOUGHT. NEITHER THE PUBLISHER NOR THE AUTHOR SHALL BE LIABLE FOR DAMAGES ARISING HEREFROM. THE FACT THAT AN ORGANIZATION OR WEBSITE IS REFERRED TO IN THIS WORK AS A CITATION AND/OR A POTENTIAL SOURCE OF FURTHER INFORMATION DOES NOT MEAN THAT THE AUTHOR OR THE PUBLISHER ENDORSES THE INFORMATION THE ORGANIZATION OR WEBSITE MAY PROVIDE OR RECOMMENDATIONS IT MAY MAKE. FURTHER, READERS SHOULD BE AWARE THAT INTERNET WEBSITES LISTED IN THIS WORK MAY HAVE CHANGED OR DISAPPEARED BETWEEN WHEN THIS WORK WAS WRITTEN AND WHEN IT IS READ.
For general information on our other products and services, please contact our Customer Care Department within the U.S. at 877-762-2974, outside the U.S. at 317-572-3993, or fax 317-572-4002. For technical support, please visit https://hub.wiley.com/community/support/dummies
.
Wiley publishes in a variety of print and electronic formats and by print-on-demand. Some material included with standard print versions of this book may not be included in e-books or in print-on-demand. If this book refers to media such as a CD or DVD that is not included in the version you purchased, you may download this material at http://booksupport.wiley.com
. For more information about Wiley products, visit www.wiley.com
.
Library of Congress Control Number: 2019934591
ISBN 978-1-119-55516-2 (pbk); ISBN 978-1-119-55519-3 (ebk); ISBN 978-1-119-55522-3 (ebk)
So you want to learn to code — awesome! Coding — writing computer programs — has something for everyone: creativity, logic, art, math, storytelling, design, and problem solving. From games and simulations to helpful tools and electronic gadgets, this book coaches you step by step through coding real programs in real programming languages that you can share with family and friends.
Many kids want to learn to code, but not every kid has computer programming classes at school or a camp he or she can attend during the summer. That’s where this book comes in!
Coding for Kids For Dummies will help you learn all of the basic coding ideas and skills used by real computer programmers. Everything you do here will be useful in learning new skills and more advanced programming languages in the future. Best of all, the tools in this second edition are free, available online, and easy-to-use.
This edition of the book covers the following:
Additionally, graphic design and animation are incredibly important skills that go hand-in-hand with coding to create great-looking and easy-to-understand digital tools. Although this book provides a little bit of guidance in these areas, the main focus of the content in these pages is coding.
Hello person buying this book and reading this intro! I assume you are a kid who wants to learn to code. Awesome! You are starting on an adventure that will take you from being a user of technology to being a maker of technology. And it’s a lot easier than you might think.
Here are a few other assumptions I make about you (or your technology) as you get started:
Lastly, if you struggle with spelling and punctuation — and you’re operating in text-based mode — you may need to spend extra time troubleshooting your code for misspellings. The IDE for a programming language can give you clues about which commands it doesn’t understand, but you will need to pay special attention to the details.
As you work through the projects in this book, you’ll see four icons. These icons point out different things.
On the Dummies.com website, I give you some extra goodies that you won’t find in this book. Go online to www.dummies.com/cheatsheet/codingforkids
for a cheat sheet of coding commands in Scratch and JavaScript. (You can also type Coding for Kids cheat sheet in the search bar at www.dummies.com
.) Download the information, print it, and keep it with your computer!
You can work on the projects in order, or you can jump around and work on any project you choose. After you gain a little experience coding, you can go in a bazillion new directions. Learn more advanced concepts in Scratch and JavaScript. Make up your own projects. Work on learning more advanced programming languages.
I hope this book inspires you to continue learning more about coding and making things with tech. Kudos on taking the first step! Now go get started!
Part 1
In this part you’ll …
CHAPTER 1
You know that coding has to do with building the apps you use and controlling the technology in your life, but what exactly is coding? Coding, also known as computer programming, is creating instructions for a computing device to do something. You use a language to communicate with other people, and computers use a coding language to communicate. And just as you can learn to write, speak, and understand languages different from the one you first learned as a toddler, you can learn to communicate in a coding language — so that you can “talk to” computers!
You’re probably wondering whether coding is hard to learn. The answer is that it’s easy to get started with coding, and easy to write real computer programs to perform all sorts of tasks! Unlike the early days of coding, when computer programmers talked to computers using long sequences of numbers (0s and 1s), you can now write code by using words and symbols that you can understand easily. For example, you can tell an app to play a sound three times (“boom boom boom!”) with a command such as repeat 3 (play sound boom)
. Neat, huh?
This type of human-friendly coding, which is called a high-level language, is what you will use when you're first learning to code. (Many professional programmers also use high-level languages.) Later, I talk more about high-level languages and the languages you’ll use in this book.
You’re probably also wondering whether you can make anything cool as a new coder. Yes, you can! In this book, you write code to build games, toys, and electronic gadgets. Everything you create you can play with and share with your friends and family.
This book is filled with great projects you can do to learn the basics of coding and make real apps. You’ll be using two programming languages to code: Scratch and JavaScript.
In the Scratch language, you build code with blocks (also called tiles) that snap together to make complete programs. Scratch is a learning language, created especially for kids, and has its own integrated development environment (IDE), which is a fancy name for a place where you write and test code.
JavaScript is a professional programming language that real coders use to make all sorts of things from apps to websites. You will use two easy-peasy IDEs to code in JavaScript: App Lab and MakeCode. As with the Scratch IDE, these JavaScript IDEs let you work in block mode, snapping together your coding commands. But when you feel ready to tackle text-based coding — typing your commands — you can switch to text mode in App Lab and MakeCode.
You can create your code in Scratch, App Lab, and MakeCode on any computer or tablet. Just be sure you have a good Internet connection, and you’re ready to go! You learn more about the basics of working with each language and programming environment in Chapter 2.
A computer program consists of the instructions you code to make a computer do something. A program looks like a list of steps, filled with words and symbols. Many words in the list will be familiar, such as for
, if
, and forever
. Words in a computer program are called commands because you're commanding the computer to perform some sort of action. Some commands look like combinations of words you know, smushed together into new words. For example, JavaScript uses the onEvent
command to find out whether a user has pressed a button.
You might also recognize many of the symbols in a computer program. These look like operators you use in math class (+, -, >. =) and also like punctuation marks you use in English class, such as a period (.) and a semicolon (;).
All of the commands and symbols in a computer program are organized in a special order so that the computer can understand what it is supposed to do. Planning that order and then coding it is a bit like writing an essay, solving a math problem, performing dance choreography, or running a play in football. You have to put together and execute (run) the program in a specific order — you can’t just put the instructions anywhere and expect the program to work correctly.
Historically, the first computer program a new coding student writes is one that prints the words “Hello World!” on the computer screen. Figure 1-1 shows an example of what that code looks like in Scratch, and its resulting output (what it displays onscreen).
Figure 1-2 shows the same code in JavaScript (in block mode and in text mode) using the App Lab IDE, and its resulting output.
Figure 1-3 shows the same code in JavaScript (in block mode and in text mode) using the MakeCode IDE, and the output when displayed on the micro:bit electronics board. Because the micro:bit can scroll only one letter at a time, the figure displays only the letter H at the beginning of “Hello World!”
You’ll be making little programs like this, and much bigger programs too, in no time!
Many mornings, I cook chocolate chip pancakes for my family, following a recipe I created myself. A recipe is like a computer program, and following the recipe is like executing the program. The recipe has parts, including gathering and measuring ingredients, mixing the ingredients to make the pancake batter, and then dropping spoonfuls of the batter onto the griddle to cook it. Similarly, a computer program has parts such as asking the user for information, doing something with that information, and then telling the user the result.
Within each part of a program, you write small chunks of code to perform different processes. A chunk of code that performs a task is called an algorithm. For example, one algorithm I perform when making pancakes is testing the surface temperature of the griddle: I plug in the griddle, set it to a certain temperature, and drip a few droplets of water onto the surface to see how quickly they evaporate.
Constructing algorithms is important in coding programs to run on a computer. Think about the types of algorithms you might make in a favorite game you play on your phone. For instance, an algorithm you might code in a Yahtzee game is rolling the dice. Or an algorithm you might code in a Space Invaders game is flying a spaceship across the sky every so often.
The algorithms you create connect with each other to build your entire program. As coders, we have three fancy terms to describe how our algorithms connect: sequence, selection, and repetition. Here’s what each means:
Throughout the book, you’ll see references to sequence, selection, and repetition. Check back here to refresh your memory of how each is used when coding a program.
As you plan and develop your programs, you’ll need to have some organized way of writing them down. You can use several methods to represent a program before you translate it into code for use on a computer.
Some people like to draw a picture or a series of pictures (called a storyboard) to show how an app, a game, or a website will look onscreen. This type of work is often performed by graphic designers, the people who make the images and the animations for computer programs. You will be doing your own graphic design work for the programs you code in this book, so think about doing a little drawing before you touch the keyboard to code.
Other people like to build a flowchart or write pseudocode when planning their programs. A flowchart is like a little map with special boxes and arrows that describe the main parts of the program. Table 1-1 shows some of the most important flowchart symbols and what each symbol represents.
Table 1-1 Symbols Used In Flowcharts
Symbol |
Name |
What It Means |
Arrow |
Shows the program sequence |
|
Terminal |
Starts or ends the program |
|
Process |
Performs a task |
|
Decision |
Makes a decision, such as yes or no |
|
Input/output |
Accepts input or produces output |
|
Preparation symbol |
Sets up a loop counter |
In this book, a couple of programs are planned by using a flowchart. Figure 1-4 is a simple example of a flowchart for a program in which a user searches for, and plays, a song. The great thing about planning a program with a flowchart is that it helps you think about the overall operation of the program. You can think visually and leave writing code for later!
Another strategy for planning a program is to jot down your overall ideas in a simplified form of computer code, called pseudocode, which means fake code. It’s not code that the computer can run, but it is written similarly. When writing pseudocode, you don’t have to worry about punctuation such as semicolons or curly brackets, so it keeps your mind on the overall operation of the program — not the fine details.
For example, if you code part of a Simpsons game in which Homer is eating donuts, you might write some pseudocode that looks like this:
create variable donuts = 0
if Homer eats donuts
then add one to donuts
if donuts > 10
then print "Stop eating donuts!"
else print "Have another donut!"
Whether you choose to draw pictures, flowchart your program, or write pseudocode, it’s a good idea to put your plan on paper in some organized form before you start coding.
Although coding is about creating new ideas and bringing them to life through computer programs, remember that it’s also about your mindset as a coder. Just as you prepare yourself to run a race or compete in a spelling bee, you can do certain things to get ready to code. Here are a few:
Coders make the apps you buy in the app store, but what else do they make? The list of cool things you can create with code is long! For the computer, you can build online games, personal and small business websites, and virtual tours of your photo galleries. For everyday gadgets, you can build backpack alarms, handheld games, health monitors, weather sensors, pet trackers, and remote fish feeders.
If you’re into textiles and sewing, you can code programs that control LED lights sewn into fabric so you can craft crazy Halloween and spirit day costumes that literally light up any room you enter! If you’re all about security and secret agent activities, you can go cyber, learning Internet basics and encryption techniques to keep online transmissions secure, and information private.
If you have a flair for the theatrical, you can write code to control robots to dance onstage while flying synchronized drones overhead in a stage production. If you love home electronics, you can code devices for use in your smart home, from camera monitors to mood music automated by time of day.
If you want to get wild, you can design, wire, and code an entire yard full of holiday lights, festive music, projection images, and moving figures for the annually televised Great Christmas Light Fight!
And what about those apps in the app store? You can make all sorts of games, from puzzles to wordplay to arcade games. You can build helper tools that assist people with their daily lives. If you’re a good Samaritan, you can code apps to connect people in need with available resources, especially in times of crisis. The programs you can code are limited only by your imagination and your skill set.
As a young coder, you can build simple versions of many of these amazing toys and tools today. By doing so, you’ll not only have fun and feel the satisfaction of making a real, usable product but also build the foundation for your future.