Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Introducing JavaScript Finishing the Game Adding Animated Characters

How do can I determine the exact position "coordinates" I need to use?

For example, if I want a coin right in this spot, then how do I know which x and y values exactly I need to use?

3 Answers

Mohammed Munier Hamoud Shikh
Mohammed Munier Hamoud Shikh
1,616 Points

You can bring a paper and draw a rectangle (8 cm width,6 cm height) , 1cm=100 pixel. then divide it with roller , every 1 cm draw a line, in the end you will have a grid , every connect point have a value. That's the same thing with those values in Screen. http://1.bp.blogspot.com/_TDPzTFmd880/TVB5MtBIAHI/AAAAAAAAApM/wsA3HUzULtU/s400/grid.PNG Ask me if you have another question, i am new also but it is better to work together

Antonio Vargas
Antonio Vargas
Courses Plus Student 4,174 Points

I have this idea in my head to create a javascript code that will put a grid on the page and the cursor can tell you the exact position of the coordinate. But that is way ahead of my current skills. lol. I'm sure someone already created the code, just have to google it.

Saiful Azhar
Saiful Azhar
2,510 Points

You must first be able to get the element itself, which is this using javascript own

var elem = document.getElementsByTagName("em")[0];


var elem = document.getElementsById("em")[0];

or any other selector.

Then, having the element, you can call

var result = elem.getBoundingClientRect();

Which you'll then be able to access all 4 dimension of the elements coordinates

console.log(result.top, result.right, result.bottom, result.left)

Sorry... I just started with the course so this is like Chinese to me! Guess asking this Q was a bit ahead of me... but thank you, I'll refer back to it later when I have learned more.