html - Can't call function from body onload (uncaught reference error: start is not defined) javascript -
i have body onload calling function in javascript. have tried many things, console prints error log: uncaught reference error: start not defined. think might malfunction, please notify me if works you. code follows:
<!doctype html> <html> <head> <title>monster invasion</title> <script type="javascript"> var hur; var monsters = 10; var objective = false; var health = 100; var damage = 30; var sheild = false; var ea = 1; function start() { settimeout(hurt,4000) } function hurt() { var newhelth = health - damage; health = newhelth; document.getelementbyid("healtw").innerhtml = health; start(); } function kill() { if(monsters > 0) { monsters--; document.getelementbyid("monster1").src="dead.jpg" settimeout(next,2000) }else { objective = true; document.location="endoflevel.html"; } } function next() { document.getelementbyid("monster1").src="monster.jpg" } } </script> </head> <body onload="start()"> <p id="healtw"></p> <embed src="guide_first_level.mp3" type="audio/mp3" hidden="true" autostart="true"> <a id="st" onclick="kill()"><img id="monster1" src="monster.jpg"></a> <p id="ada"></p> <a href="sheild.html">activate sheild</a> </body> </html>
your script type wrong
try
<script type="text/javascript"> </script>
but don't need mention script type
just use plain script tag
like
<script> </script>
one more thing add before end of script tag give }
.
just remove it
function next() { document.getelementbyid("monster1").src="monster.jpg" } } // <-- remove bracket </script>
Comments
Post a Comment