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

202
Views
¿Cómo se pone un contador de clics en un último nodo secundario para contar cuántas veces se hace clic en el último nodo?

estoy haciendo un juego de coincidencia de caras y quería encontrar una forma de contar cuántas veces elegiste en el mensaje de alerta. ¿Pondría la información del código de conteo en la función Game Over o haría una nueva función para ponerla en el último niño? solo del lado izquierdo?

 <body onload='generateFaces()'> <h1>'Matching Game'</h1> <p>'Click on the extra face on the left.'<p> <div id='leftSide'></div> <div id='rightSide'></div> <script> let numberOfFaces = 5; const theLeftSide= document.getElementById('leftSide'); const theRightSide= document.getElementById('rightSide'); function generateFaces(){ for (let i=0; i < numberOfFaces; i++) { const face= document.createElement('img'); face.src= 'image/smile.png'; const randomTop = Math.floor(Math.random()*400) +1; const randomLeft = Math.floor(Math.random()*400) +1; face.style.top = randomTop + 'px'; face.style.left = randomLeft + 'px'; theLeftSide.appendChild(face); } const leftSideImages = theLeftSide.cloneNode(true); leftSideImages.removeChild(leftSideImages.lastChild); theRightSide.appendChild(leftSideImages); theLeftSide.lastChild.addEventListener('click', nextLevel); document.body.addEventListener('click', gameOver); } function nextLevel() { event.stopPropagation(); numberOfFaces += 5; while (theLeftSide.lastChild) { theLeftSide.removeChild(theLeftSide.lastChild); } while (theRightSide.lastChild){ theRightSide.removeChild(theRightSide.lastChild); } generateFaces(); } function gameOver() { alert('GaMe OvEr! !\n Zombie ipsum reversus ab viral inferno, nam rick grimes malum cerebro. De carne lumbering animata corpora quaeritis. Summus brains sit​​, morbo vel maleficia? De apocalypsi gorger omero undead survivor dictum.'); document.body.removeEventListener('click', gameOver); theLeftSide.lastChild.removeEventListener('click', nextLevel); } </script> </body>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Deberá declarar una variable para almacenar cuántas veces un usuario ha hecho clic en el último nodo. Por ejemplo let num = 0; Y luego una pequeña adición en su función nextLevel() , es decir, num = num + 1; . Para mostrarlo en la pantalla, debe declarar una etiqueta HTML separada. Luego puede ir con document.getElementById('clicked').innerText = num + ' times user has clicked'; . Funcionará correctamente.

about 4 years ago · Juan Pablo Isaza Report
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!