First of all, this is my first question here, so I want to Apologize in advance if it is repeated.
I have a piece of code like this:
$("#one").click(function(){
randomNumber = Math.floor(Math.random()*6)+1;
$("#two").click(function(event){
console.log(randomNumber);
});
});
First time everything is working fine, but second time i executed that It shows the first random number and then the second, etc.
#twoon each click of#onehence you see theconsole.logbeing executed multiple times. What behaviour are you trying to create?$("#two").one('click', handler);but surely you have better to do, depending what exact behaviour you are expecting, like e.g what are you expecting if clicking on #two before any click on #one??? And beware, here you are definingrandomNumberon global scope