How do I call a function just once?

  • 0
    Hello, the code below calls setTimeout as many times as the user has clicked on the element, but the task is to call the function once after complete execution of setTimeout, and not as many times as the user wants. How to do it?

    game_start() {
    		const arr_bet = [];
    		for ( let bet of ) {
    			bet.addEventListener('click', (e) => {
    				const bet_value =;
    				const bet = arr_bet.reduce((sum, current) => {
    					return sum + current;
    				}, 0);
    				setTimeout((e) => {[0].classList.add('hidden');[1].classList.add('hidden');
                                            // Здесь по идее должна вызываться функция.
    				}, 10000);
    JavaScript Isabella Kerr, Nov 20, 2019

  • 1 Answers
  • 0
    Make some kind of flag. Which is false by default. On each execution, check this flag, if from still false - execute the function in which the flag is toggled to true

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!