Introduction [2/10]
Learn to Code, Here and Now!
To get started, run the provided program by simply clicking the “Run” button.
Afterwards, click the “Next” button to proceed.
Welcome to your computer programming journey!

To run the program, simply click the “Run” button.
The source code for this program consists of two statements, each on its own line.
Notice how the editor automatically colors the source code. This feature is known as “syntax highlighting”, and it helps you read code more easily.
The println (P-R-I-N-T-L-N) statement is used to display text on the screen (println is short for print line).
The disc function is used to draw a disc. The position and size of the disc are specified by arguments.
Exercise:
Let’s add a little more to the program. Try adding the following statement: disc( 600,150, 100 , /red );
This is a complex program which performs a series of computations
to produce a short animation.
[Run the program]
The complete text of the program is known as the source code. Source code usually contains multiple statements that work together to produce the desired output.
Let's make a simple modification.
Exercise:
Locate the second statement in the source code, the one which contains the word ZedLX. Change this word to some other word, as you like. After making your change, run the program.
* * *
You you can easily share this animation with your friends by using the Share button above the source code.
You should then enter a title for your program in the provided field. Feel free to leave any other fields blank if you prefer.
Then, click on the “Create Link” button to generate a unique link to your program. Click on the link to see your program in action! To share your creation with others, use the sharing buttons available on the “Execution Completed” page.
Run the program to see it in action.
In programming, the term “to print out” actually means “to display information on the screen”.
A text enclosed in quotation marks is called a string. Strings are printed on the screen exactly as they are written.
In addition to strings, a println statement can also print expressions. Expressions can use various operators, for instance +, -, *, / .
Important Notes:
- Plain statements must be ended with a semicolon (;)
- When printing multiple items, separate them with a comma (,)
This program contains an error. Don’t worry, this is a normal part of the coding process.
Click the Check button to get a hint about what might be wrong. The automatic verifier will analyze the code and provide feedback.
Correct the error and run the program.
Hint: Sometimes, the verifier will offer helpful suggestions. In this case, pay close attention to the advice it provides.
Solution...
Many times, the actual error is located just before the reported one. This is one such case.
The error is in the third statement: it is missing a semicolon (;) symbol at the end.
println "Up above the world so high," ;
In programming, the operator * is
used to denote multiplication.
[Run the program]
Round brackets (), also called parentheses, can be used to group expressions.
Square brackets [] or curly brackets {} (also known as braces) cannot be used to group expressions.
Exercise:
Display the result of expression 15*3+2*(90+10)
In the first statement, the program prints the numbers 12 and 7 together.
Without any separation, they appear as number 127.
[Run the program]
A way of separating the results would be to add some space between the numbers.
For a more enjoyable reading experience, we recommend using fullscreen mode. You can enter fullscreen by pressing the F11 key. To exit fullscreen, simply press the F11 key again.
Exercises:
1. Add the following statement: println "Jammed together:" , 2, 5, 1+1;
2. Add the following statement: println "Un-jammed: ", 2," ",5," ",1+1;
This program outputs the expressions together with the results.
[Run the program]
At first glance, it might seem that the strings contain expressions, but that is just an illusion. Strings cannot contain expressions, they only contain text.
Strings are printed out as they are written. Expressions are evaluated, and then their results are printed.
Exercise:
Add the statement: println "3m × 4m = ", 3*4, "m²";
It looks like this program contains an error.
Click the Check button to view the error description.
Correct the error, then run the program.
Helpful Hint: While the error report may seem difficult to understand this time, the automatic verifier has actually provided an excellent clue.
Solution (click):
println 8 +(10 - (2+7));
This program produces a simple animation.
The source code contains many unexplained features.
[Run the program]
Let's make some small changes to the source code.
Important Note:
Keep in mind that all names are case-sensitive.
For example, purple
is not the same as PuRpLe,
nor Purple nor PURPLE).
Exercises:
1. Change the Disc Color: Modify the color of the disc to purple.
[Run the program]
2. Change the Speed: In the source code of this program, the number 6 is
the step of the for loop.
Change this value to 2 in order to slow down the motion.
[Run the program]
<< F2:Prev - - F4:Next >>