I'm working on my HTML & JavaScript project.
When I run my code, I have an error which is
"Cannot read property 'appendChild' of null".
I tried to solve this problem, and I found here, but I can't understand because I'm beginner of programming, and I'm not good at English.
Here's my code:
<html>
<head>
<script language="javascript">
var wordlist = [ "a", "bb", "ccc", "dddd" ];
var rannum = Math.floor(Math.random() * wordlist.length);
var x = document.createElement("INPUT");
for(i = 0; i < wordlist[rannum].length; i++) {
x.setAttribute("type", "text");
x.setAttribute("value", "");
document.body.appendChild(x);
}
</script>
</head>
<body>
</body>
</html>
Could you help me to solve the problem?
Thank you in advance.