Below are various ways of neat commenting:
let x = 99; // assign numerical value to x
let y = x + 2; // assign the sum of x + 2 to y
// Print "Hello, World!" to the console
console.log("Hello, World!");
// Function to add two numbers
function addTwoNumbers(x, y) {
let sum = x + y;
return sum;
}
// Initialize a function
function alphabetizeOceans() {
// Define oceans variable as a list of strings
const oceans = ["Pacific", "Atlantic", "Indian", "Antarctic", "Arctic"];
// Print alphabetized array to the console
console.log(oceans.sort());
}
/* Initialize and invoke a the greetUser function
to assign user's name to a constant and print out
a greeting. */
function greetUser() {
const name = prompt("What is your name?");
console.log("Hello ," + name + "! How are you?");
}
/**
* Initialize constant with an array of strings.
* Loop through each item in the array and print
* it to the console.
*/
const seaCreatures = ["Shark", "Fish", "Octopus"];
for (const seaCreature of seaCreatures) {
console.log(seaCreature);
}