Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

234
Vistas
How do I make this button respond and run the listed function?

I would like the button I created to simply document "Heads" or "Tails" based off my function.

<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 Respuestas
Responde la pregunta

0

So First you need to create another element where you would display your result, than you need to create a function and assing this function on to a button with the onclick event like so -> if you want to change the text in the button just change the id of the button

    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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda