There is a task: Paragraphs with numbers are given. By the first click on a paragraph, the square of the number it contains should appear in it. By the second click - cube. By the third click - the fourth degree.
My code is:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> <body> <p>3</p> <p>7</p> <p>9</p> <script> var elems = document.getElementsByTagName('p'); for (var i = 0; i < elems.length; i++) { elems[i].addEventListener('click', func1); elems[i].addEventListener('click', func2); elems[i].addEventListener('click', func3); } function func1() { this.innerHTML = this.innerHTML * this.innerHTML; this.removeEventListener('click', func1); } function func2() { this.innerHTML = Math.pow(this.innerHTML, 3); this.removeEventListener('click', func2) } function func3() { this.innerHTML = Math.pow(this.innerHTML, 4); this.removeEventListener('click', func3) } </script> </body> </html> My functions run at the same time. How to make them work alternately?