I'm totally new to web dev and trying to learn and practice Javascript. I've learned a trick to change displayed image by changing the src of the image (they are named: pic-0.jpg, pic-1.jpg, pic-2.jpg... so on) but somehow my code won't work. Anyone can have a look at my codes, help me out and give me some advice. I'd appreciate it!
Here are the codes:
var counter = 0;
document.getElementById('btn-next').addEventListener('click', changeImg);
function changeImg() {
counter++;
document.getElementById('picture').src = 'pic-' + counter + '.jpg';
}
<body>
<section class="container">
<div class="picture-container">
<img src="pic-0.jpg" id="picture" alt="">
</div>
<button id="btn-previous">Previous</button>
<button id="btn-next">Next</button>
</section>
<script src="r.js"></script>
</body>
cheers and many thanks!