Simply put, I have three images, and I'd like to cycle through them when I click on the image. In other words, I want the img src to change to the next specified image when it is clicked on. However, this doesn't happen. Keep in mind all of the images I have are in the same folder as my html code, and each image loads just fine by themselves, they just won't cycle through.
Here is my code:
<!Doctype html>
<html>
<head>
</head>
<body>
<p>Hello world</p>
<img onclick="changePic()" id="pika" src="pichu.gif" alt="pichu">
<script>
function changePic() {
var pika = document.getElementById("pika").src;
if(pika == "pichu.gif") {
pika = "pikachu.gif";
} else if (pika == "pikachu.gif") {
pika = "raichu.gif";
} else {
pika = "pichu.gif";
}
}
</script>
</body>
</html>