What am I doing wrong that you click the “click” the color changes only once?
<p id="klik">Click</p>
<div id="block">example text change color</div>
<script>
document.getElementById('klik').onclick=function(){
setTimeout('ppp()', 1000);
}
function ppp() {
var index = Math.round(Math.random() * 3);
var ColorValue = "green";
if(index == 1) ColorValue = "red";
if(index == 2) ColorValue = "lime";
if(index == 3) ColorValue = "yellow";
document.getElementById("block").setAttribute("style","color:" + ColorValue);
}
</script>