12. Challenge Task

The code in script.js logs all even numbers (from 2 to 24) to the JavaScript console. There seems to be a lot of redundant code in the file. Rewrite (or refactor) the code using a loop.
console.log(2);
console.log(4);
console.log(6);
console.log(8);
console.log(10);
console.log(12);
console.log(14);
console.log(16);
console.log(18);
console.log(20);
console.log(22);
console.log(24);

Solución

/**
Notar que el número va de 2 en 2, hasta llegar a 24
*/

for (let i = 2; i <= 24; i += 2) {
console.log(i);
}

Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.