I am trying to make a Cookie Clicker game where when I click an image of a cookie, it adds 1 to a score variable. Every time I click on the cookie, it deletes the image. Can anyone explain this to me, and how to fix it?
<!DOCTYPE html>
<html>
<head>
<title>Cookie Clickers</title>
<script>
function myFunction() {
var score = 0;
score++;
document.write(score);
}
</script>
</head>
<body>
<img src="cookie.jpg" id="cookie" onclick="myFunction()">
</body>
</html>