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 Object-Oriented JavaScript: Challenge Making the Game Interactive moveLeft() and moveRight() Methods Solution

George Roberts
George Roberts
Full Stack JavaScript Techdegree Student 8,474 Points

Why does ```this.html.style.left``` hold an integer, and not a string value with 'px' included?

Hi, Below is my attempt at the moveLeft() method. I thought that this.html.style.left would need to hold a string because the units (pixels) need to be included. Am curious why that's not necessary in this case? Thanks

    if (this.columnLocation > 0) {
      this.htmlToken.style.left = (this.offsetLeft - 76) + 'px';
      this.columnLocation -= 1;

good question, unfortunately I don't know the reason either. It seems to be added automatically. When I inspect the element with the chrome developer tools it does have the 'px' added even though I did not explicitly add them myself.

Although if i edit it manually in the dev tool it also works if i leave out the px.