Computer Discoveries, Unit 3, Lesson

Hi, I’m a little confused about a bit of code for CSD Unit 3, Lesson 7, Step 11:

var greenAlien = createSprite(100, 200);
var pinkAlien = createSprite(300, 200);

// Setting Up Drawing

function draw() {
pinkAlien.rotation = randomNumber(-5, 5);
greenAlien.rotation = randomNumber(-5,5);
I initially set my fill as white but then change it to red. But my ellipses stay white. Why?

Link to the project or level:
What I expect to happen: stars should change fill color from white to a new color
What actually happens: stars stay the same color as outside the draw function
What I’ve tried:

Hi @rkane,

So, the order of the blocks still matters even inside the draw loop. Have you tried changing the order of your blocks a little?


Hi Mike
Thanks for responding. My thought process is that outside the draw loop, I’ve initially set the fill color to white. So when we 1st step into the draw loop, the first call of ellipse will be white. But then I change fill to red, so the 2nd and subsequent loops through the draw function should draw the ellipse as red, shouldn’t it? Or does it keep reverting back to the call to white each time we start the draw loop?

Logically, your explanation makes sense but my understanding is that each time the Draw loop is invoked, it is using default values (from outside the loop) until you define them otherwise, so it isn’t remembering commands from one iteration of the draw loop to the next.


Right on. That was a little nuance that I didn’t get. Thanks Mike!

1 Like