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

232
Views
¿Cómo hago que este botón responda y ejecute la función enumerada?

Me gustaría que el botón que creé simplemente documente "Cabeza" o "Cola" según mi función.

 <button id="coinFlipper">Flip a Coin</button> <script> const coinFlip = function() { let randomNumber = Math.random() if (randomNumber < 0.5) { document.write("Heads") } else { document.write("Tails") } } </scipt>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Entonces, primero debe crear otro elemento donde mostraría su resultado, luego necesita crear una función y asignar esta función a un botón con el evento onclick así -> si desea cambiar el texto en el botón simplemente cambie la identificación del botón

 const coin =()=>{ let randomNumber = Math.random(); if (randomNumber < 0.5) { document.getElementById("result").innerHTML = "Heads"; } else { document.getElementById("result").innerHTML = "Tails"; } }
 <button onclick="coin()" >Flip a Coin</button> <p id="result"></p>

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!