Preview:
function sumToN(n) {
   let sum = 0;
   for (let i = 0; i <= n; i++) {
      sum += i;
   }
   return sum;
}

console.log(sumToN(3));
//Notice that sumToN does not print anything; the output comes from the final line of the program, which prints the value returned by the function call sumToN(3).

function isEven(n) {
   if (n % 2 === 0) {
      return true;
   } else {
      return false;
   }
}

console.log(isEven(4));
console.log(isEven(7));
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter