Everybody say "Hello!"

Let's look at some most basic JS statements. In the code editor window to the right of this tutorial page, you should have the following code:

// Chapter 1, First JS program
console.log('Hello, Buzz Coder!');
console.log();
console.log("Hello, CodeCraft!");

Click the run button at the top. In the console window below the code editor, you will see this text:

Hello, Buzz Coders!  

Hello, CodeCraft!

console.log()

console.log() is a JS built-in function. It shows the data in the console window. When you type console.log(), you are calling a function.

Here, the contents in the parenthesis are called parameters or arguments. In the second console.log() function, the empty parenthesis means there are no parameters, so it printed out a blank line.

The parenthesis are always required when calling a function in JavaScript, even if there are no parameters.

Now let's write some code. At the end of the file, start a new line and add a console.log() statement to print out your own name: Hi, my name is ____.

In JavaScript, it's commonly considered a good habit to terminate each statement with a semicolon ; sign.

Run the program again to see your message. It should look like this:

Hi, my name is Buzz.

alert()

alert() is another JS built-in function, it's not frequently used in CodeCraft programs, but it's often used in ordinary JS programs, so we'll mention it here.

alert() is very similar to console.log(), it will also show the message that is provided in the parenthesis. The difference is that alert() shows the message in a pop up window, and you have to respond by clicking the 'ok' button to let the program continue.

Try this:

alert(Welcome to Buzz world!)

results matching ""

    No results matching ""