I find this simple "for loop" exercise.
Using a for loop print all even numbers up to and including n. Don’t include 0.
let n1 = 22; // Example output: // 2 4 6 8 10 12 14 16 18 20 22 OR each item on a new line
I found a way to solve this but I don't think its elegant at all.
Here is my code:
let n1 = 22;
for (let i = 0; i < n1; i++){
let b = i * 2;
if (b <= n1){
if (b == 0) {} else
{ console.log('Count',b);}
};
};
How can I improve it?