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

Ben Os
Ben Os
20,008 Points

I don't work in strict mode, but still, if something is messed up in the code, even deep, I the code won't work

I have the code:

console.log("hi");

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

When I check this in a page, it doesn't work even partially: i.e, even the console message won't appear.

Yet, if I remove the second part of the code (the if statement), a console message does appear.

My question is why, a later, bad part, makes an earlier good part not to be processed and how could I avoid that, that is, how could I make the browser's Js interpreter to show all good code (above the first piece of bad code) anyway?

Maybe some kind of a directive (a distant relative of "use strict" but in this case "be even less strict").

Guil Hernandez Dave McFarland

Moderator edited: Question edited to remove profanity but retain the original meaning. Markdown added so that the code will render properly in the forums.

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi Ben! I have slightly modified the original question in order to remove the profanity, but retain the original meaning, and I also went ahead and added some markdown to the question to make your code a bit easier to read. If you have a moment, take a peek at the Markdown Cheatsheet link at the bottom :arrow_down: of the "Add an Answer" box to see some tips and tricks on formatting your post. :sparkles:

Ben Os
Ben Os
20,008 Points

Hi Jennifer. I am not sure what profanity you refer to. Can you please email me. I really have no idea what you are talking about... Please email me about this through my email enlisted in the Treehouse system.

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

I am not Staff, so I do not have access to your email, Ben. But the word I'm referring to started with an "f" and was followed by the word "up". :smiley:

1 Answer

Steven Parker
Steven Parker
229,582 Points

There's no "ignore syntax errors" option in JavaScript.

A syntax error always invalidates the entire script. You just have to be sure your code is correct before you publish it.

In this case, you have two issues:

  • you can't use CSS units in JavaScript, values in JavaScript are unitless.
  • there's no "width" propery of window, you probably want "innerWidth".

Only the first one is an actual syntax error.

Ben Os
Ben Os
20,008 Points

Hi Steven. Thanks. Can you please share some more information on the unit vs unit having vs the unitless issue in CSS vs Js or at least share an article you find decent on this? I'm not sure what is the best phrase to look with.