I'm pretty new to javascript and my problem is that when I try to create a button with 2 functions using an if else loop, it doesn't work for me, I have tried other people's code which to me looks the exact same and theirs works. I haven't been able to find anything about what I might be doing wrong.
The button works the first time, changing the image to the second one, but isn't able to revert it to the original when I click it again.
<head>
<script>
var btn, photo;
function initButton(){
btn=document.getElementById("btn");
photo = document.getElementById("photo");
btn.addEventListener("click", change);
function change(){
if(photo.src = "images/play.png"){
photo.src = "images/pause.png"
} else {
photo.src = "images/play.png"
}
}
}
window.addEventListener("load", initButton);
</script>
</head>
<body>
<button id="btn">photo</button>
<img src="images/play.png" height="300px" id="photo"/>
</body>