Velvet Star Monitor

Standout celebrity highlights with iconic style.

general

5.6.5 Coordinates, Answer In Comments (CodeHS)

Writer Sophia Terry

The prompt of the assignment is "Write a program that shows the X and Y coordinates of the mouse in a label on the top left of the screen. You should update the values of the coordinates whenever the mouse moves." The basic code I have laid out is:

var pos;
function start(){ mouseMoveMethod(mousePos);
}
function mousePos(e){ pos = new Text("((" + e.getX() + "," + e.getY() + ")"); pos.setPosition(75, 75) add(pos);
}

It "works" but it just keeps adding text over top of the new text instead of updating the existing text. I know I'm missing something, but I just cannot figure out what to implement to make it work the way it needs to. I've been stuck for days :(

1 Answer

I got it!!! I just needed to think smarter LOL

var pos;
function start(){ pos = new Text(" "); pos.setPosition(75, 75) add(pos); mouseMoveMethod(mousePos);
}
function mousePos(e){ pos.setText("(" + e.getX() + "," + e.getY() + ")");
}

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy