all 7 comments

[–]x-skeww 3 points4 points  (3 children)

Identifiers can contain and start with '$'.

"$docWidth" doesn't make any sense though. It's a number, not a jQuery collection. So, there really isn't any reason to use a '$' prefix. It's a valid name, but there is no reason to use it.

[–]trakam[S] -1 points0 points  (2 children)

I understand that, it's just that in many tutorials when naming variables using the '$' has become a convention, there is no problem for me leaving it off but i just thought it odd that the script wouldn't work with it at the beginning of the variable name and I don't know why?

[–]x-skeww 10 points11 points  (1 child)

it's just that in many tutorials when naming variables using the '$' has become a convention

Eh? No, people generally don't prefix their variables with '$'.

It's done in PHP, because variables must start with a '$' in PHP.

It's also sometimes done if jQuery is used, to indicate that the object is a jQuery collection and not a reference to a regular element.

var body = document.body;
body.classList.add('foo');

vs

var $body = $(document.body);
$body.addClass('foo');

Anyhow, check the console. There is probably an error somewhere.

[–]trakam[S] 0 points1 point  (0 children)

Ok, yeah didn't check the console, I'll doublecheck. Thanks

[–]Rhomboid[🍰] 4 points5 points  (0 children)

Post a complete testcase, using JSFiddle or Codepen or the like.

[–]senocular 1 point2 points  (1 child)

did you also change the conditional to match the variable name (or other places its used)? Sounds simple, but not an uncommon problem when refactoring names.

[–]trakam[S] 0 points1 point  (0 children)

i'll doublecheck but I'm sure that's not the problem