1 of 11

Unit 5

Lesson 7 Loops Practice

2 of 11

To do: December 17

#1 What is the output of the following code snippet?

for(var i=0; i<5; i++)

{

var num = randomNumber(1,10);

console.log(num);

}

3 of 11

To do: December 17

#2 - How can you revise the code so that only even numbers are printed in the console?

for(var i=0; i<5; i++)

{

var num = randomNumber(1,10);

console.log(num);

}

4 of 11

To do: December 17

#2 - How can you revise the code so that only even numbers are printed in the console?

for(var i=0; i<5; i++)

{

var num = randomNumber(1,10);

if(num % 2 == 0)

{

console.log(num);

}

}

5 of 11

Go over homework

  • Submit Parts of a For Loop notes in IN (image/pdf)
  • Complete Code.org Lesson 6 bubbles 1-3
  • goFormative U5L06 Loops Investigate

6 of 11

var steps = 0;

while(steps < 4){

moveForward();

steps++;

};

A for loop combines these three parts into one statement

for (var i=0; i<4; i++){

moveForward();

};

Any variable name can be used here. It’s most common to use i.

A loop is an example of iteration: a repetitive portion of an algorithm which repeats a specified number of times or until a given condition is met.

Unit 5 Lesson 6 - Activity

7 of 11

Lesson 7 Loops Practice

8 of 11

Unit 5 Lesson 7 - Activity

Debugging: the process of finding and fixing problems in code

Describe

The Problem

What do you expect it to do?

What does it actually do?

Does it always happen?

Hunt

For Bugs

Are there warnings or errors?

What did you change most recently?

Explain your code to someone else

Look for code related to the problem

Try

Solutions

Make a small change

Document

As You Go

What have you learned?

What strategies did you use?

What questions do you have?

9 of 11

Unit 5 Lesson 7 - Activity

Debugging Loops

Use console.log to print out important information.

Track your iterator variable in the Watch panel.

Run your code slowly so you can see how your loop is actually working.

10 of 11

Unit 5 Lesson 7 - Activity

Loops Practice - U5L07 bubbles 1-8

Do This:

  • Lesson 7 bubbles 1-8 using pair programming
  • Let me know when you’re done with bubble 7.

11 of 11

Class work due at the end of the day

  • Complete Code.org Lesson 7 bubbles 1-7.
  • goFormative U5L07 - Loops Practice

Lists and Loops quiz on Tuesday, January 4