Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

246
Views
Repeating a function after it ends

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

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!