Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
I need help with this CodeHS Caterpillar JavaScript problem: https://answers.yahoo.com/question/index?qid=20141104073413AAMKOTS?
2 Answers
- 6 years ago
var NUM_CIRCLES = 15;
// This graphics program should draw a caterpillar. A caterpillar has NUM_CIRCLES
// circles. Every other circle is a different color, the even circles are red, and
// the odd circles are green. Use a for loop to draw the caterpillar, centered
// vertically in the screen.
function start(){
var kRadius = getWidth() / (NUM_CIRCLES * 2);
for(var i = 0; i < NUM_CIRCLES; i++){
var circle = new Circle(kRadius);
circle.setPosition( i * kRadius * 2 + kRadius, getHeight() / 2);
if(i % 2 == 0){
circle.setColor(Color.red);
}
else{
circle.setColor(Color.green);
}
add(circle);
}
}