comment
// Comments are used document your code so it is easier for humans to understand. You should include a comment at the start of each function to explain what the function does, if it takes any arguments, and if it returns any values. It is also a good idea to comment any complex blocks of code so you, or another programmer, can more easily maintain or modify the code in the future.
Examples
Example of comments with sprites
Alien Sprite Project
// Create two alien sprites and assign them animations
var alienBlue = createSprite(100, 200);
alienBlue.setAnimation("alienBlue");
alienBlue.rotation = 15;
var alienGreen = createSprite(250, 275);
alienGreen.setAnimation("alienGreen");
alienGreen.rotation = -15;
// Draw a space background and planets
background("darkblue");
noStroke();
fill("yellow");
ellipse(375, -50, 300, 300);
fill("darkgreen");
ellipse(125, 75, 100, 100);
fill("blue");
ellipse(350, 350, 150, 150);
// Add joke text
fill("white");
textSize(20);
text("What kind of music do planets sing?", 25, 125);
text("Neptunes!", 200, 200);
drawSprites();
Syntax
// Comment
Tips
- You can type whatever you want on a comment line.
- You can comment out a block of statements using /* before the first statement and */ after the last statement.
Found a bug in the documentation? Let us know at support@code.org.