Extra Practice

Remember: Learning to program takes practice! It helps to see concepts over and over, and it's always good to try things more than once. We learn much more the second time we do something. Use the exercises and additional self-checks below to practice.

1. Looping and Conditionals

let maxNum = 20;

for (let i=1; i<=maxNum; i++) {
    if (i % 2 === 0) {
        console.log(`${i} is even.`;
    } else {
        console.log(`${i} is odd.`);
    }
}

What is the name of the counter variable in this for loop?

maxNum i console undefined The name of the counter variable is i.

How many times will this loop execute?

1 19 20 21 This loop will execute 20 times.

What is the starting value of i?

0 1 20 undefined The starting value of i is 1.

What is the conditional statement checking for?

That the remainder of i divided by 2 is 0. That the remainder of maxNum divided by 2 is 0. That i divided by 2 is 0. That i divided by 2 is even. The conditional is checking that the remainder of i divided by 2 is 0.

What happens to i on each loop?

It is decreased by one. It is increased by one. It is multiplied by 2. It is multiplied by 10%. The variable i is increased by one on each iteration of the loop.

What would the loop output when i equals 7?

"7 is even." "7 is odd." When i is equal to 7, the console log would be "7 is odd.".

What would the loop output when the condition (i % 2 === 0) equals false?

`${i} is even.` `${i} is odd.` When (i % 2 === 0) equals false, the console log would be `${i} is odd.`.

Visit Content Online

The content on this page has been removed from your PDF or ebook format. You may view the content by visiting this book online.

results matching ""

    No results matching ""