Category: Functions
Writes a decription of some code.
// 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.
// Let's you know your code is running. console.log("It's Alive!");
Example: Roll Two Die Call functions that use randomNumber(1,6) to simulate rolling two die and summing the results.
// Call functions to generate two die rolls and sum the result. Display the value on the console. console.log(rollDie() + rollDie()); function rollDie() { // Define a function that uses randomNumber(1,6) to randomly generate a die roll, 1 to 6, and return the value. var roll = randomNumber(1,6); return roll; }
// Comment
You can type whatever you want on a comment line.
Comments are ignored by the computer.
Found a bug in the documentation? Let us know at documentation@code.org
Found a bug in the documentation? Let us know at documentation@code.org