JavaScript: Your First Program

JavaScript is a programming language used by web browsers to make a webpage become interactive and respond to the live input of the user.

Check out these examples of really cool webpages with JavaScript: www.hereistoday.com/, www.patatap.com/ and www.cubeslam.com/iutuna.

In this post you will learn how to write your very first JavaScript program (of course, if you haven’t done so already).

This program involves writing a “cat face” which as a result of your written instructions to the computer will replicate itself by 10 times.

The code to be written is the following:

var drawCats=function(howManyTimes) {
for(var i=0; i<howManyTimes; i++){
  console.log(i + "=^.^=");
  }
};

drawCats(10)

The following are the instructions for this program:

  1. Open Google Chrome.
  2. On the address bar, write about:blank and press enter.
  3. Then, to open Google Chrome’s JavaScript Console (the platform where you will be writing your program), press the J key on your keyboard while holding both the CTRL and SHIFT keys at the same time.
  4. Write the code above. When you reach the end of the line do not press the ENTER key of your keyboard as that will execute only the one line of code you have just written. To make a new line press and hold both the SHIFT and ENTER keys at the same time.
  5. Once all the lines of your program have been written, hit the ENTER key to execute your program and see the result!

In the near future we will discuss certain words used by this program and why it works.