Controls
Help
JavaScript Cheatsheet
Basics
- Each command ends with a semicolon (
;) - Syntax is C-like, but without types
- One-line-comments with
// COMMENT_TEXT - Multi-line-comments with
/* COMMENT_TEXT */
Variables
- Set variables:
var NAME_OF_VARIABLE; - Set variable in current block (
function,if,else,while, etc.):let NAME_OF_VARIABLE; - Change variables:
NAME_OF_VARIABLE = CONTENT_OF_VARIABLE;
Control flow
- Simple check with
if ( CONDITION ) { PROGRAM_CODE } CONDITIONcan be:NAME_OF_VARIABLE == CONTENT_OF_VARIABLE(there are two equal signs!)- Simple loop:
while ( CONDITION ) { PROGRAM_CODE }
Functions
- Define functions:
function FUNCTION_NAME ( ARGUMENTS ) { PROGRAM_CODE } - Execute functions:
FUNCTION_NAME( ARGUMENTS ) - Arguments are only necessary when also defined in the function
Functions to control the robot
moveForwards()
Moves the robot one unit forwards.
turnRight() and turnLeft()
These functions are for turning the roboter.