- 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
sum
by2
. - Inside the condition, after increasing the sum, log the
'even number'
string in the console. - After the check is complete, add the
else
branch and increase thesum
inside it by1
. - Inside the
else
, after increasing thesum
, log the'odd number'
line in the console.
Comments