r/codehs • • Nov 15 '22

5.9.6 Concentric Circles

It says that "Half of your circles should be red." and I'm pretty sure I have 1 too many of red circles but idk how to fix this, please help.

18 Upvotes

12 comments sorted by

2

u/Fabulous_Crazy_1574 Mar 24 '23

there is a prob with the radius after fixing the while loop

→ More replies (1)

2

u/IInNeedOfHelp Sep 25 '24

ik its been 2 years and all, but to anyone that finds this and has the same issue, this is how i fixed it (likely not very optimised):

function main()

{

let count = 0;

let radius = 200;

let circB = new Circle(radius);

circB.setPosition(getWidth()/2, getHeight()/2);

circB.setColor("red");

add(circB);

let circG = new Circle(radius-180);

circG.setPosition(getWidth()/2, getHeight()/2);

circG.setColor("black");

add(circG);

while(radius > 40)

{

radius = radius - 20;

let circ = new Circle(radius);

circ.setPosition(getWidth()/2, getHeight()/2);

circ.setColor("black");

add(circ);

radius = radius - 20;

let circ2 = new Circle(radius);

circ2.setPosition(getWidth()/2, getHeight()/2);

circ2.setColor("red");

add(circ2);

}

}

main();

→ More replies (2)

1

u/djdjndndd Nov 17 '22

Change the first one to any color instead of red because that is why is is making more red than black

2

u/NOXILOL_ Nov 29 '22

It helps thank you so much

2

u/tbobila Jan 26 '23

Preciate that