cannot read property 'value' of null in console
I have a code which runs perfectly on other platforms , but when I try to run the same code in Sololearn Code playground it shows a message: "cannot read property 'value' of null" in console and don't show the output. Actually I make divs inside divs using javascript. So I searched for it and got a solution in Stack Overflow. I implemented it. But the code still not working. Is this possible that same code can show the error (cannot read property 'value' of null) in different plateforms? My code: var ab=document.getElementById('comments'); var comment = document.createElement('div'); comment.setAttribute('class', "comment"); ab.appendChild(comment); Replaced code: var str; var ab=document.getElementById('comments'); var comment = document.createElement('div'); comment.setAttribute('class', "comment"); if (ab != null){ str= ab.appendChild(comment); } else { str = null; } https://stackoverflow.com/questions/22057610/uncaught-typeerror-cannot-read-property-value-of-null