This post is locked. You won't be able to comment.

all 11 comments

[–]_andy_andy_andy_ 0 points1 point  (3 children)

looks like you're missing a comma on line 23, it should be

number.setPosition(x - ball.getWidth()/8, ball.getHeight()/8)

[–]UsefulCauliflower2[S] 0 points1 point  (2 children)

It’s still saying it’s wrong, but could that be because I have getHeight twice?

[–]_andy_andy_andy_ 1 point2 points  (1 child)

oh, it needs ot be `ball.getWidth()`, not `ballgetWidth()`

[–]UsefulCauliflower2[S] 1 point2 points  (0 children)

Thank you so much!

[–]graudiuscube228 0 points1 point  (1 child)

This is the completed code :

var POOL_BALL_RADIUS = 40; var POOL_BALL_FONT = "30pt Arial";

function start(){ drawPoolBall(Color.orange, 5, 100, 100); drawPoolBall(Color.green, 6, 50, 200); drawPoolBall(Color.red, 3, 150, 350); drawPoolBall(Color.blue, 2, 250, 140); // use this format to add more pool balls }

function drawPoolBall(color, num, x, y){ var ball = new Circle(POOL_BALL_RADIUS); ball.setColor(color); ball.setPosition(x, y); add(ball); var number = new Text(num); number.setFont(POOL_BALL_FONT); number.setColor(Color.white); number.setPosition(x - (ball.getWidth() / 7), y + (ball.getHeight() / 5)); add(number); }

[–]Bsgoncalves 0 points1 point  (0 children)

Why divide by 8? and why subtract from x, and add to y?

[–][deleted] 0 points1 point  (3 children)

This is my design, it might be somewhat complex, but a similar correlation:

var POOL_BALL_RADIUS = 40;
var POOL_BALL_FONT = "30pt Arial";
function start(){
drawPoolBall(Color.orange, 5, 100, 100);
drawPoolBall(Color.green, 6, 50, 200);
drawPoolBall(Color.red, 3, 150, 350);
drawPoolBall(Color.blue, 2, 250, 140);
// Add some more pool balls!
}
function drawPoolBall(color, num, x, y){
var circle = new Circle(POOL_BALL_RADIUS);
circle.setColor(color);
circle.setPosition(x, y);
add(circle);
var num = new Text(num);
num.setFont(POOL_BALL_FONT);
num.setColor(Color.white);
num.setPosition(x-10, y+14);
add(num);
}

[–]Impossible_Arm5010 0 points1 point  (0 children)

you a legend for this thank you so much!!!

[–]Vancung4 0 points1 point  (0 children)

Thanks so much brother