I'm trying to do a simple javascript game and this is the code for loading next level after completation of the previous one. I was expecting it to check what is the current level and based on that skip to the next level. It's not working properly. Actually it seems that the first two if statements are working but I can't say the same for the last one: it does nothing.
document.getElementById('next').addEventListener('mouseup', function(){
if(location.pathname==="/level0.html"){
location.assign("/level1.html")
}
if(location.pathname==="/level1.html"){
location.assign("/level2.html")
}
if(location.pathname==="/level2.html"){
location.assign("/level3.html")
}
})
/*some css here*/
<button id="next">NEXT LEVEL</button>I even tried to use "else if" statements but it's not working neither.
if(location.pathname==="/level0.html"){
location.assign("/level1.html")
}
else if(location.pathname==="/level1.html"){
location.assign("/level2.html")
}
else if(location.pathname==="/level2.html"){
location.assign("/level3.html")
}
else{
location.assign("/index.html")
} I also read the documentation about location property but I don't understand where could be the problem. Can someone help me understand please?
Thanks
Aucun commentaire:
Enregistrer un commentaire