Review of the Previous Hour

Before we start this new lesson, let's quickly review what we learned in the Hour of Code: JavaScript Basics course:

// Review of the Previous Hour
// print out a string
console.log('Hello, Buzz Coder!');

//print out a number
console.log(28);

// assign value to a variable
let x = 15;

// then print the value
console.log(x);

Comment

Comments are lines of a code that the computer ignores when you run the program. Comment lines starts with //. They are useful when you want to add notes to your program or disable a piece of code that you don't want to run for now.

In the CodeCraft editor, the first line of a file automatically becomes the name of the file, so it's a good idea to write the title of the file there as a comment.

console.log() function and data types

console.log() is one of JavaScript's many built-in functions. We can print out some data like a string or a number in the console window.

Assign value to a variable

let variable_name = value;

You can think of variables as containers that hold values such as numbers, strings, and other types of data.

Function basics

All functions have a pair of parentheses following its name. The parentheses may enclose some variables or values as the parameters of the function, or they may be left empty.

Function Calls

To execute, or run, the function, you need to call its name and provide input values for the parameters in the parentheses. If there are no required input parameters, leave the parentheses empty (but they must exist).

Setting up CodeCraft

The following code places one brick block inside CodeCraft 3D game world:

// CodeCraft Setup
let game = new Game();
let materials = game.materials;
console.log(materials);

// A black block for your reference:
let p = new Position(0, 1, -20);
game.setBlock(p, 1);

Note: if you need to clear all structures in the game world, simply refresh the browser.

results matching ""

    No results matching ""