This tutorial hasn't been translated.
This tutorial is licensed under CC BY-NC 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.
We'll keep using the same project from the previous part. You can edit the code block in the On start of layout event by double-clicking it, changing the code, and then clicking outside or pressing Ctrl + Enter to finish editing. Then you can preview the project and open the browser console in developer tools to see the results. It's worth getting familiar with this process, as we'll be relying on it a fair bit. Try out the following code snippets this way to see how they work.
Sometimes the code snippets will tell you to try them out in the browser console. In this case don't enter them to your code block in Construct - preview the project, open the browser console, and try typing each line of the code snippet in there instead.
You can put two statements on the same line, as it's the semicolon that really separates statements. However conventionally there is a single statement per line.
Anywhere two forward slash characters // appear indicates a single-line comment. Everything from the forward slash characters up to the end of the line is a comment. The comment can occupy its own line or come after some code.
// This is a single-line comment!
console.log("Hello world!"); // And this!
This tutorial guide will often use these kinds of comments to annotate code, indicating what it does or what result some code will produce.
Single-line comments naturally end at the end of the line, so if you want a long comment, you need to comment every line:
// First line of comment
// Second line of comment
// Third line of comment
Multi-line comments can be an easier way to write this. Multi-line comments start with a forwards slash and asterisk /* and end with an asterisk and forward slash */.
/* First line of comment
Second line of comment
Third line of comment */
Despite the name, you can also write this kind of comment on a single line. This can be useful as you can still write code after the end of the comment.
/* comment before code */ console.log("Hello world!");
console.log(/* comment inside code */ "Hello world!");
In general, you can put comments anywhere you like and it won't affect the code. As you may have found with event sheets too, adding comments is often a good idea to help yourself or other people understand the code. Professionally written code is often heavily commented to help anyone reading it understand how it works. The best code is clear and easy to understand, not obscure and complicated.
Congratulations!! Very Clear and Objective in the explanations!!!
You might consider including "scope" in the "VAR" section and why "var" is quirky.
As explained in part 1 this tutorial isn't intended to go in to detail about the quirks of old legacy features. If you stick to let/const then you don't need to learn about all those quirks.
You're right ... it's going down the "rabbit hole". Thanks for your rapid reply.