Variables

Learn how to store and work with data using variables in natural language.

Variable Declaration
Create variables using simple English syntax
Pattern:
variable_name is equal to value
Variables are automatically declared when first assigned. No type declarations needed.
User Input
Get values from users at runtime
Basic Pattern:
initialise variable_name with user input
With Custom Prompt:
initialise variable_name with user input "Your prompt message:"
With Type Specification:
initialise variable_name as type with user input
Combined:
initialise variable_name as type with user input "Your prompt:"

User input allows you to get values from users while your program is running. The browser will show a prompt dialog asking for input.

Supported types: number, boolean, string (default)

If no type is specified, the input is treated as a string. For boolean input, enter "true" or "True" (case-insensitive).

Supported Data Types
The language automatically detects data types

Numbers

age is equal to 25
temperature is equal to 98.6
count is equal to -5

Integers and decimal numbers are supported.

Text (Strings)

name is equal to "John"
message is equal to "Hello, World!"
empty is equal to ""

Text must be enclosed in double quotes.

Boolean (True/False)

is_student is equal to true
is_complete is equal to false

Use `true` or `false` (lowercase).

Expressions

sum is equal to x plus y
full_name is equal to first_name + " " + last_name

Variables can be assigned the result of expressions.

Variable Naming Rules
Guidelines for choosing variable names

✓ Good Names

age
student_name
total_score
is_valid
max_attempts

✗ Avoid

x
temp
data1
thing
variable

Naming Rules

  • • Use descriptive names that explain the variable's purpose
  • • Use lowercase letters and underscores (snake_case)
  • • Start with a letter, not a number
  • • Avoid spaces and special characters
  • • Use boolean names that read like questions (is_valid, has_data)
Updating Variables
How to change variable values after declaration

Reassignment

counter is equal to 0
print counter
# Update the value
counter is equal to 5
print counter

Simply assign a new value using the same syntax.

Mathematical Updates

score is equal to 10
score is equal to score plus 5
print score

Use the variable in expressions to update based on its current value.

Increment and Decrement

counter is equal to 0
increment counter
print counter
decrement counter
print counter

Special commands for adding or subtracting 1.

Variable Scope
Understanding where variables can be used

Global Variables

name is equal to "Alice"
if age is greater than 18 then
print name + " is an adult"
endif

Variables declared outside blocks can be used anywhere in the program.

Block Variables

if score is greater than 90 then
grade is equal to "A"
print grade
endif
# grade is not accessible here

Variables declared inside blocks (if, for, while) are only available within that block.

Best Practices
Tips for working effectively with variables
Tip

Initialize variables before use

Always assign a value when declaring a variable to avoid errors.

Tip

Use meaningful names

Choose names that make your code self-documenting and easy to understand.

Tip

Be consistent with naming

Use the same naming pattern throughout your program (e.g., always use snake_case).

Tip

Group related variables

Declare related variables near each other for better code organization.

Common Variable Patterns
Frequently used variable patterns and their purposes

Counter Variables

count is equal to 0
attempts is equal to 0
total_items is equal to 0

Track how many times something happens.

Accumulator Variables

sum is equal to 0
total_score is equal to 0
product is equal to 1

Build up a result over multiple operations.

Flag Variables

found is equal to false
is_complete is equal to false
has_error is equal to false

Track true/false states or conditions.

Temporary Variables

temp is equal to a
a is equal to b
b is equal to temp

Store intermediate values during calculations.