I am trying to use the JavaScript code from a .js file.
My code works fine when I keep this code in the .html file within the script tags.
What changes should I make when I move the script to a .js file.
HTML:
<!DOCTYPE html>
<html>
<head>
<title>Cat Clicker</title>
<script type="text/javascript" src="js/app.js"></script>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<div id='cc'><img src="images/cat1.png"><br /></div>
<div>The number of times you clicked the cat is:</div><br />
<div id='times'>0</div>
</body>
</html>
JS:
var pic = document.getElementById('cc');
pic.addEventListener('click', function() {
var count = document.getElementById('times').innerHTML;
count = parseInt(count) + 1;
document.getElementById('times').innerHTML = count;
}, false);