- script.js
JavaScript
var sum = 0;
for (var i = 1; i <= 10; i++) {
console.log('i: ' + i);
// Add a check here
console.log('sum: ' + sum);
}
Result
Goalscompleted
- Inside the loop, add a check to make sure that the counter is even (
i % 2 === 0). - If the check is executed, increase the variable
sumby2. - Inside the condition, after increasing the sum, log the
'even number'string in the console. - After the check is complete, add the
elsebranch and increase thesuminside it by1. - Inside the
else, after increasing thesum, log the'odd number'line in the console.
Comments