+ 2

Debugging help needed - with a project.

Recently was working on a mini-project that showcase different sorting methods & small information about each method. I stored html content in the JavaScript files, due to that whenever the users/I refresh on the compiler it just turns the browser that the compiler creates to display my project blank. Any reasons on why that's the case? The project: https://www.sololearn.com/en/compiler-playground/WV5mU14m312y

21st Apr 2025, 5:11 PM
Shamironi
Shamironi - avatar
1 Réponse
+ 3
The code link you attached's not properly accessed, because of proper attachment. But I find your code from your code bits. JavaScript runs immediately when encountered in the <head> or at the top of the <body>. If your script tries to access an element before the DOM is built, document.getElementById() returns null. The reason's the DOM parsing is sequential. Scripts execute before the element exists. That's a bug. First to solve this just put the script in same page like; <!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <script> // Write your script here in this skeleton </script> </body> </html> Second just keep you script in the js section just put your whole code inside a function like this; window.addEventListener('load', checkJSLoaded) function checkJSLoaded() { // Write your whole script here } https://sololearn.com/compiler-playground/W0UDzzgseIPw/?ref=app https://sololearn.com/compiler-playground/Wbp9y4E8MIYA/?ref=app
23rd Apr 2025, 4:23 AM
`ᎎᔗᔗዚ
`ᎎᔗᔗዚ - avatar