greenzeta.com
10 PRINT "HELLO"
20 GOTO 10
console.log('This is my message');
var myAwesomeVariable;
myAwesomeVariable = 42;
var myAwesomeVariable = 42;
var myAwesomeVariable = 'Some text I wrote.';
var myAwesomeVariable = true;
var myAwesomeVariable = {name: 'Matt'};
var myAwesomeVariable = null;
var myAwesomeVariable;
myAwesomeVariable = 'Awesomeness!!!';
console.log(myAwesomeVariable);
myVariable = 40 + 2;
myVariable = 40;
myVariable = myVariable + 2;
var myNumber;
myNumber = 21;
myNumber = myNumber * 2;
console.log(myNumber);
someNumber == 42
42 == 42
33 != 42
66 > 42
33 < 42
Let's use a comparison operator to complete a conditional statement.
if( someNumber == 42 ){
// do something
}
A line that begins with // is called a “comment.” Comments are notes for humans to read and are ignored by the computer.
var myName = 'Matt';
if( myName == 'Matt' ){
console.log('I know you.');
}
if( myName != 'Matt' ){
console.log('I do not know you.');
}
if( myName == 'Matt' ){
console.log('I know you.');
}
if( myName != 'Matt' ){
console.log('I do not know you.');
}
if( myName == 'Matt' ){
console.log('I know you.');
}else{
console.log('I do not know you.');
}
!(lastName == 'Smith')
(firstName == 'John') || (lastName == 'Wilber')
(firstName == 'Matt') && (lastName == 'Wilber')
var firstName = 'Matt';
var lastName = 'Wilber'
if( (firstName == 'Matt') && (lastName == 'Wilber') ){
console.log('I know you.');
}else if( (firstName == 'Matt') || (lastName == 'Wilber') ){
console.log('Have we met before?');
}else if(!(firstName == 'Matt') && !(lastName == 'Wilber')){
console.log('I do not know you');
}
One of the things computers do best is repeating tasks over and over again. You can make a computer repeat things by writing an instruction called a "loop".
The instructions that are repeated in the loop must eventually change a condition to false. The false condition will end or "break" the loop.
One type of loop is called a "while loop". Like a conditional statement, a while loop executes a group of instructions if a condition is met. The loop will repeat those instructions over and over until the condition is not met.
while( [logical operation is true] ){
// instructions to repeat
}
var counter = 0;
while( counter < 10 ){
console.log('The counter is ' + counter);
counter = counter + 1;
}
You use brackets to define an array and commas to separate its items
var myArray = [ 'a', 'b', 'c' ];
myArray[0]
var counter = 0;
var letters = ['j', 'a', 'v', 'a', 's', 'c', 'r', 'i', 'p', 't'];
while( counter < letters.length ){
console.log(letters[counter]);
counter = counter + 1;
}
function MyFunction()
function SaySomething(){
console.log("HelloWorld");
}
function SaySomething(){
console.log("HelloWorld");
}
SaySomething();
function SaySomething(){
console.log("HelloWorld");
}
SaySomething();
SaySomething();
SaySomething();
function SaySomething(thingToSay){
console.log(thingToSay);
}
function SaySomething(thingToSay){
console.log(thingToSay);
}
SaySomething("Hello");
SaySomething("Hello Again");
SaySomething("Goodbye");
function add( addend1, addend2 ){
var sum = addend1 + addend2;
return sum;
}
var result = add( 3, 5 );
console.log('The sum of 3 and 5 is ' + result);
Source Code
Follow @greenzeta on Twitter
greenzeta.com
Phaser Website