Iteration Popcorn Hacks Answer Key
Iterations Popcorn Hacks Answer Key
%%javascript
for (let i = 1; i <= 10; i++) {
console.log(i);
}
<IPython.core.display.Javascript object>
%%js
function sumNumbers(n) {
let sum = 0;
for (let i = 1; i <= n; i++) {
sum += i;
}
return sum;
}
console.log(sumNumbers(5)); // Output should be 15
<IPython.core.display.Javascript object>
%%js
const names = ["Alice", "Bob", "Charlie", "Diana"];
for (let i = 0; i < names.length; i++) {
console.log(names[i]);
}
<IPython.core.display.Javascript object>