I am new to JavaScript
I am trying to print an array using a function document.getElementById
I am getting an error Uncaught TypeError: Cannot set properties of null (setting 'innerHTML') at call.html:10:58
<!DOCTYPE html>
<html>
<head>
<title>My information</title>
<body>
<h1>My name is Luffy</h1>
<p>I am a software developer</p>
<script>
const programmingLanguage = ["Python", "Java","C"];
document.getElementById("program").innerHTML=programmingLanguage;
</script>
</body>
</head>
</html>
please help me where did i go wrong
CodePudding user response:
The problem is that, you are trying to get an element which has the id program, but there is no element which has the id as program
.
You can create an element with id program
. this will resolve the error.
<!DOCTYPE html>
<html>
<head>
<title>My information</title>
<body>
<h1>My name is Luffy</h1>
<p>I am a software developer</p>
<p id="program"></p>
<script>
const programmingLanguage = ["Python", "Java","C"];
document.getElementById("program").innerHTML=programmingLanguage;
</script>
</body>
</head>
</html>