Issue connecting Javascript file with html

Dear colleagues,
I’m currently on the exercise of personal portfolio and I’m stuck on connecting my JavaScript file to Html.
I have tried with no success.
Can you please check and let me know if you see what I’m doing wrong?

here is the printscreen of the error

here is the link on html

Best

did you try opening the html file in a browser? or using a browser extension?

hi, yes, my html file is opened in the browser but i still receive that error

check if the html file and the JavaScript file are in the same folder.

Yes both files are in the same directory

Looking at the error message in the first screenshot, I think the issue has to do with the runtime environment. You are trying to run the application in a Node.js environment which does not has a document object, thus the error message message:

ReferenceError: document is not defined

You need to run the application in the browser where the document object exists. I see you are also using the VS Code plugin Code Runner which is great but it runs your JavaScript application in a Node.js environment. Here is an another great plugin by Microsoft which will run your application in the browser. Live Preview - Visual Studio Marketplace.

FYI: The Live Preview plugin launches your application in the editor (like a Split View) by default. To configure it to launch your application in your default browser, open VS Code > Settings > [search for ‘live preview’] in the ‘Search Setting’ field > scroll down the page until to get to the section: [Live Preview: Open Preview Target]. Click the dropdown and select [External Browser]

3 Likes

thanks a lot this help

1 Like

You are welcome, happy coding!

1 Like