I want to repeat a function after it ends however most answers I found relied on Setinterval which would work if the time taken to complete the function would be the same every time which in my case is not true as it relies on user input, I've tried calling the function at the end of the code that works only on my device once I resize the window and click it again it breaks the code resulting in a page crash.
Code!!
const onClick = function () {
iad = this.id;
console.log(iad);
switch (iad) {
/*1*/ case "Sharpie":
pre[0].innerHTML = "You chose Scissors";
pimg[0].src = "/assets/sharpie.png";
ph1[0].innerHTML = "Scissors";
sel = 1;
break;
/*2*/ case "Rock":
pre[0].innerHTML = "You chose " + rok;
pimg[0].src = "/assets/pngwing.com.png";
ph1[0].innerHTML = this.id;
sel = 2;
break;
/*3*/ case "Paper":
pre[0].innerHTML = "You chose " + pap;
pimg[0].src = "/assets/hand.png";
ph1[0].innerHTML = this.id;
sel = 3;
break;
}
cmp()
}
function cmp(){
switch (rnd) {
case 1:
cimg[0].src = "/assets/sharpie.png";
ch1[0].innerHTML = "Scissor";
console.log(sel)
if(sel == 1 ){
pre[0].innerHTML = "Its a Draw!";
}
if(sel == 2){
pre[0].innerHTML = "You won!"
}
if(sel == 3){
pre[0].innerHTML = "You Lost! lol"
}
break;
case 2:
cimg[0].src = "/assets/hand.png"
ch1[0].innerHTML = "Paper";
console.log(sel)
if(sel == 1 ){
pre[0].innerHTML = "You Won";
}
if(sel == 2){
pre[0].innerHTML = "You Lost! lol"
}
if(sel == 3){
pre[0].innerHTML = "Its a Draw! "
}
case 3:
ch1[0].innerHTML = "Rock";
ch1[0].innerHTML = "Rock";
cimg[0].src = "/assets/pngwing.com.png";
console.log(sel)
if(sel == 1 ){
pre[0].innerHTML = "You Lost! lol";
}
if(sel == 2){
pre[0].innerHTML = "Its a Draw"
}
if(sel == 3){
pre[0].innerHTML = "You won"
}
}
}
Thank's
-Zejh