For Rookies
Computers are just machines and they need to be told what to do. Coding is simply telling the computer what to do.
Just like there are many human languages, there are many programming languages. We will be learning JavaScript, which is a great language for beginners. It was originally designed for web browsers, but today is used all over the place, in games, app, servers, and even in space.
Functions
Most computer programs are made up of commands, called functions. To run a function in JavaScript, type its name followed by parentheses.
For example, if you want to hear a trumpet sound, you can try this command:
Make sure your sound is on and hit the play button!
Parameters
Sometimes, functions need extra information called parameters. Imagine telling someone to walk. You would also need to say how many steps or which direction to go. These are parameters. Parameters go inside the parentheses.
The speak()
function tells the browser to say something, but we need
to tell it what to say. Try changing the text inside of the quotes. Remember, the
computer has to do whatever you tell it to!
Coordinates
If you were to hold a magnifying glass up to your computer screen, you would see it is made up of tiny little dots called pixels. When drawing on the screen, we use coordinates to tell the computer where to draw. We count pixels from the left edge—the x coordinate—and from the top edge—the y coordinate.
For example, the star()
function draws a star on the screen, but we
need to say where to draw the star, and how big to make it.
Try changing the numbers and watch the star move and change size.