Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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
PLUS
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];

or

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.