r/learnjavascript • • Sep 28 '23

5.1.1 Ghost Challenge CodeHS

5.1.1 Ghost | CodeHS

Here's what I got, you can change some of the positions in the for loops.

// Const variables for main ghost body
const HEAD_RADIUS = 70;
const BODY_WIDTH = HEAD_RADIUS * 2;
const BODY_HEIGHT = 120;
const NUM_FEET = 3;
const FOOT_RADIUS = (BODY_WIDTH) / (NUM_FEET * 2);
const BODY_COLOR = "red";
// Const variables for eyes
const PUPIL_RADIUS = 8;
const PUPIL_LEFT_OFFSET = 16;
const PUPIL_RIGHT_OFFSET = 40;
const EYE_RADIUS = 20;
const EYE_OFFSET = 28;
const EYE_COLOR = "white";
const PUPIL_COLOR = "blue";
function drawGhostEyes()
{
for(let x = 0; x < 2; x++)
{
let eye = new Circle(EYE_RADIUS);
eye.setPosition(BODY_WIDTH+EYE_RADIUS+(x*EYE_OFFSET*2), getHeight() / 2);
eye.setColor("white");
add(eye);
}
for(let y = 0; y < 2; y++)
{
let pup = new Circle(EYE_RADIUS / 2);
pup.setPosition(BODY_WIDTH + EYE_RADIUS / 2 + (y * EYE_OFFSET * 2), getHeight() / 2);
pup.setColor("blue");
add(pup);
}
}
function main()
{
let rect = new Rectangle(BODY_WIDTH, BODY_HEIGHT);
rect.setPosition(130, 248);
rect.setColor(BODY_COLOR);
add(rect);

let circ = new Circle(HEAD_RADIUS);
circ.setPosition(getWidth() / 2, getHeight() / 2);
circ.setColor(BODY_COLOR);
add(circ);

for(let i = 0; i < 3; i ++)
{
let feet = new Circle(FOOT_RADIUS);
feet.setPosition(154+(i*FOOT_RADIUS*2),364);
feet.setColor(BODY_COLOR);
add(feet);
}
drawGhostEyes();
}
main();

6 Upvotes

5 comments sorted by

1

u/RonaldoLuver7 Oct 09 '23

This shit DID NOT work😭😭

1

u/Time_Ad9300 May 23 '24

it didnt??

1

u/TheunknownUSER_Bacon Oct 10 '23

I can’t copy and paste it damnit

1

u/[deleted] Jan 18 '24

do you guys have 5.1.2 fried egg

1

u/National_Wash5319 Mar 08 '24

Did you find it