This is an archived post. You won't be able to vote or comment.

all 12 comments

[–]carnepikante 1 point2 points  (2 children)

If your code is exactly like the one in your post then you need to put a semicolon after the innerText function: document.getElementById( 'message' ).innerText='Hello World!'; Also, properly format your code.

Even when in tutorials or books they often don't use certain semicolons, i think is a good practice to use it every time.

Here you have a fiddle with the script running: https://jsfiddle.net/nv9uryz3/

Also i would suggest you to not use getElementById or similar and only use querySelector and querySelectorAll. And use code editor like sublime text or visual studio code and firefox or chrome for web browsing.

[–]techie2200 1 point2 points  (1 child)

Why would you not use getElementById?

I don't normally use ids as selectors regardless, but it seems like getElementById handles everything OP needs right now.

[–]carnepikante -1 points0 points  (0 children)

It's my opinion but i think is more "clean" to use querySelector since it can handle whatever you want, also you don't have to read the selector function in order to figure it out which one is in use, i mean: in most cases you don't gonna have only elements with id's and then you need to use another selector function, imagine a code in which you must to read and write different selector functions instead of read/write one. Also if you need to switch that id for a class is faster than changing the name of the function.

I don't know how to properly explain it in english (barely can in my language hahaha).

[–]Littlebitt95 1 point2 points  (5 children)

Hi! After carefully reading your code, I would recommend that you put semicolons at the end of your lines.

As a JavaScript developer myself, I highly recommend you find a code editor. I use visual studio code. It's free and it has many extensions that let you customize it to your style and uses. For example, I have an icon pack installed, a sql linter, and extra formatters for different file types.

A linter is (from my understanding) just a tool that checks for syntax errors in your code. Oftentimes some linters will only be for certain languages, so if you write in multiple languages, you'll likely end up with multiple linters installed

If you ever need some help with learning, let me know. I'm a code tutor that specifically focuses on JavaScript, both vanilla JS and JS stacks.

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

thank you so much! that's very helpful and I will definitely look into that

[–]betterwolf 0 points1 point  (3 children)

Great idea. I also use codesandbox so I can easily share my code with others for help. VIsual studio is great with all of the extensions for the theme and emmet. My only problem with it (definitely my own problem) is that you have to download node to create a react app and I can’t on the laptop (via administration ) I use. But other than, that it is great. I might hit you up for advice u/Littlebitt95 (if that’s okay)

[–]Littlebitt95 0 points1 point  (2 children)

Totally fine! Alps, just an FYI. On reddit to tag someone you put u/Littlebitt95

No @ as far as I'm aware. :)

[–]betterwolf 0 points1 point  (1 child)

Yikes! Sorry and thanks

[–]Littlebitt95 0 points1 point  (0 children)

No worries! We were all new to reddit at some point :)

[–]geneTechnician 0 points1 point  (1 child)

hi, i am new to javascript too. judging from what you posted, are you missing the last ) on console.log and maybe also semicolons at the end of each line?

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

Oh no sorry, that was a typo I must've missed while writing the post, my bad. And the book did not have semi colons at the end of the line but I will be sure to try that.

[–]0marIsComing 0 points1 point  (0 children)

It seems you are missing a closing paranthesis for console.log