Coding Global Background
Coding Global

4.6.6 Caterpillar on codeHs ReferenceError error

Archived 2 years ago
2 messages
0 members
2 years ago
Open in Discord
O
OG_Patriot

so I have everything done so far and everything works except for switching each circle color from red to blue. error says circle isent defined when I have it defined in the function below my start function and im stumped and dont know what the problem is. Need help please. code: var NUM_CIRCLES = 15; var radius = 15; var x = radius; function start(){ for(var i = 0; i < NUM_CIRCLES; i++){ createCircle(); if(i % 2 == 0){ circle.setColor(Color.red); add(circle); }else{ circle.setColor(Color.green); add(circle); } } } function createCircle(){ var circle = new Circle(radius); circle.setPosition(x, getHeight() / 2); circle.setColor(Color.red); add(circle); x = x + radius * 2; }

Replies (2)