- Joined
- Aug 16, 2022
- Messages
- 52
- Reaction score
- 2
Hi Everybody,
I'm just getting started with JavaScript but I'm frozen on this tiny example. What am, I doing wrong with it?
Both files, index.html and playtime.js are in the same directory, but the JavaScript code will not execute. It works fine as a single HTML file like this:
I'm just getting started with JavaScript but I'm frozen on this tiny example. What am, I doing wrong with it?
HTML:
<!DOCTYPE HTML>
<html>
<head>
<title>JavaScript Tests</title>
<script src="playtime.js"></script>
</head>
<body onload="countToTen()">
<h1>Lets count to TEN</h1>
<p id="theCount"></p>
</body>
</html>
Code:
JavaScript:
function (countToTen) {
var count = 0;
while (count < 10 ) {
count++;
document.getElementById("theCount"). innerHTML += count +"<br>";
}
}
Both files, index.html and playtime.js are in the same directory, but the JavaScript code will not execute. It works fine as a single HTML file like this:
HTML:
OCTYPE HTML>
<html>
<head>
<title>JavaScript Tests</title>
</head>
<body onload="countToTen()">
<h1>Lets count to TEN</h1>
<p id="theCount"></p>
<script>
var count = 0;
while (count < 10 ) {
count++;
document.getElementById("theCount"). innerHTML += count +"<br>";
}
</script>
</body>
</html>