Why is document.body null? Javascript
I created the following code: function btn(text, does) { var button = document.createElement("button"); button.innerHTML = text; button.addEventListener("click" , does ); document.body.appendChild(button); }//ends function btn function say() { document.write("text"); } btn("Click me", say ); This code results in a error: "Cannot read property 'appendChild' of null" From my googling I learned that the issues is that document.body is null (appendChild is a property of document.body but d.b is null so it cannot read it). Why is my document.body null? I think other people have been able to run this code just fine, yet it does not work for me. I have tried it on IE, Edge and Chrome. Thanks Link to this code: https://code.sololearn.com/W7QAzI0bkJs3/#js (I hope it works)