umair mohsin

umair mohsin

  • 1.4k
  • 387
  • 65.6k

javascript question

Oct 16 2016 3:04 PM
i wonna know what is the problem with this javascript code its not working until i wrote a script in a body tag. the script should run whether i wrote script in head or a body section.i don't know what is the issue.here is my code.
 
 
<html>
<head>
<title>Statements in javascript</title>
<style type="text/css"></style>
<script type="text/javascript">
var c=2;d=3,e=c+d;
document.getElementById('p1').innerHTML=e;
</script>
</head>
<body>
<p id="p1"></p>
</body>
</html>

Answers (2)