I'm aware there is an error (I've tried to preview my code on a browser and the button fails to work) but I'm unable to spot it and would like to make my code more efficient if possible.
<!DOCTYPE html>
<html>
<body>
<h1>Mood Changer</h1>
<button onclick="ChangeImage()">Change Mood</button>
<img id="myImage" src="Images/sad.png" style="width:100px">
<script>
var index = 0;
var ImageList = newArray(1);
ImageList[0] = "Images/sad.png";
ImageList[1] = "Images/smiley.png";
function ChangeImage()
{
index = index + 1;
If (index ==ImageList.length)
{
index = 0;
}
var image1 = document.getElementById("myImage");
image1.src = ImageList[index];
}
</script>
</body>
</html>