function return
Tue Jun 21 2022 21:36:35 GMT+0000 (Coordinated Universal Time)
Saved by
@cruz
#javascript
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));
content_copyCOPY
Comments