Maximiliano
Maximiliano

Reputation: 27

recursivity with jquery in a function

I am trying to create a "simon says" game, the problem is that when this function executes, the condition in the if never become true, even if I click on the buttons that push a value to the array.

function start(patron, patronl){
      if (patronl.length<patron.length){
        setTimeout(start,1000,patron, patronl);
      } else {
        patronl=[];
        patron.push(rand(1,4));
        runp(patron);
        start(patron,patronl);
      }
    }
      $("#col4").click(function(){
    patronl.push(4);
  }) 

Here is the example code of what I am trying to do

Here is my code

Upvotes: 0

Views: 33

Answers (1)

Joey Wood
Joey Wood

Reputation: 273

Instead of explicitly watching all your buttons, use an onclick. Just specify the parameters the function needs and whenever the button is clicked it will trigger that function

Upvotes: 1

Related Questions