var btnStart = document.getElementById("btnStart"); var scoreView = document.getElementById("score"); var tempsView = document.getElementById("temps"); var meme = document.getElementById("meme"); var cookie = document.getElementById("cookie"); var score; var temps; var isPlayed=false; var texte = " seconds left!"; var tailleCookieInitiale = cookie.naturalWidth; btnStart.addEventListener('click', start); cookie.addEventListener('click', clicCookie); tempsView.style.color = "red"; function start(event){ if (!isPlayed){ meme.style.display="block"; cookie.style.width = tailleCookieInitiale+"px"; temps = 15; score = 0; scoreView.textContent = score; isPlayed = true; tempsView.textContent = temps+texte; setTimeout(second,1000); } } function clicCookie(event){ if (isPlayed){ score ++; cookie.style.width = (tailleCookieInitiale+score)+"px"; scoreView.textContent = score; } } function second(){ temps --; tempsView.textContent = temps+texte; if (temps <= 0){ isPlayed = false; meme.style.display="none"; } else{ setTimeout(second,1000); } }