Reputation: 309
<!DOCTYPE html>
<head>
<title>Cookie Clicker</title>
</head>
<body>
<div id="JS"></div>
<script>
var cookies = 0;
function addCookies(){
cookies += 1;
getElementById("JS").innerHTML="Cookies: " + cookies;
}
getElementById("JS").innerHTML="Cookies: " + cookies;
</script>
<button onclick='addCookies()'>Add Cookies</button>
</body>
</html>
The addCookies()
doesn't work. It is supposed to say in the browser Cookies:
variablecookies
. Could someone explain it to me? All it shows in the browser is the button.
Upvotes: 0
Views: 70
Reputation: 708
Don't use cookies as a variable this is a reserved variable. and check the exact error through developer tool may help more.
Upvotes: 0
Reputation: 11255
There is no getElementById
function in native javascript. Use document.getElementById
method.
Upvotes: 1