Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
83
rated 0 times [  86] [ 3]  / answers: 1 / hits: 44705  / 9 Years ago, tue, july 14, 2015, 12:00:00

I have a body onload calling a function in javascript. I Have tried many things, but the console just prints to the error log: uncaught reference error: start is not defined. I think it might be a malfunction, please notify me if it works for you. My code is as 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>




More From » html

 Answers
70

your script type is wrong.


try like this


<script type="text/javascript">
</script>

However, you don't need to mention script type. just use a plain script tag.


like this


<script>
</script>

One more thing to add that before the end of the script tag, you gave an extra }.


just remove it


function next() {
document.getElementById("monster1").src="monster.jpg"
}
} // <-- just remove this bracket
</script>

[#65820] Saturday, July 11, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cristoferjordih

Total Points: 513
Total Questions: 96
Total Answers: 105

Location: Croatia
Member since Fri, Sep 11, 2020
4 Years ago
;