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

What's wrong with these two Javascript code variations?

if (window.width <= 1024px) { document.querySelector(".logo-text").innerHTML = "ForMen <br> פתרונות לגברים"; }

if (window.style.width <= 1024px) { document.querySelector(".logo-text").innerHTML = "ForMen <br> פתרונות לגברים"; }

Both seem not to work.

Console prints "Syntax error: Unexpected token".

1 Answer

Steven Parker
Steven Parker
243,656 Points

You asked this very similar question using more colorful language. :wink:

You have the same issues here:

  • you can't use CSS units in JavaScript, values in JavaScript are unitless (so leave off the "px")
  • there's no "width" propery of window, you probably want "innerWidth"
  • there's also no "style.width" property of "window"

Hi! There are similarities indeed but on the other question I meant to emphasis the issue of modes (strict / other possible non strict modes) as I've seen some of the code worked as long as bad parts were removed but didn't worked when these bad parts brought it. I really didn't mean to ask a similar question for the sake of similarity. Just used similar materials to construct the two different questions in a fast way..