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

210
Views
si no funciona al hacer un juego de dados en java script

Estoy haciendo un desafío de juego de dados en mi curso de Udemy usando javascript. Todo hasta ahora funciona bien, hice que los dados fueran aleatorios cada vez que hay una recarga. Ahora estoy tratando de hacer que el "h1" cambie a "¡SORTEO!", "¡EL JUGADOR 1 GANA!" y "¡EL JUGADOR 2 GANA!" usando sentencias if else . Pero por alguna razón, el if else no responde. Mi código: HTML:

 <!DOCTYPE html> <html lang="en" dir="ltr"> <head> <meta charset="utf-8"> <title>Dicee</title> <link rel="stylesheet" href="C:\Users\natan\Desktop\Web Development udemy\JavaScript\Dicee Challenge\styles.css"> <link href="https://fonts.googleapis.com/css?family=Indie+Flower|Lobster" rel="stylesheet"> </head> <body> <div class="container"> <h1 class ="h1">Refresh Me</h1> <div class="dice"> <p>Player 1</p> <img class="img1" src="C:\Users\natan\Desktop\Web Development udemy\JavaScript\Dicee Challenge\images\dice6.png" alt="dice6"> </div> <div class="dice"> <p>Player 2</p> <img class="img2" src="C:\Users\natan\Desktop\Web Development udemy\JavaScript\Dicee Challenge\images\dice6.png" alt="dice6"> </div> </div> <script src="./js/index.js" charset="utf-8"></script> </body> <footer> www 🎲 App Brewery 🎲 com </footer> </html>

JavaScript:

 function randomDice() { const randomNum1 = Math.floor(Math.random() * 6 + 1); const randomNum2 = Math.floor(Math.random() * 6 + 1); const img1Random = document.querySelector(".img1"); img1Random.setAttribute("src", "./images/dice" + randomNum1 + ".png"); const img2Random = document.querySelector(".img2"); img2Random.setAttribute("src", "./images/dice" + randomNum2 + ".png"); let doch1 = document.querySelector("h1").innerHTML if (randomNum1 === randomNum2) { doch1 = "DRAW!" } else if (randomNum1 > randomNum2) { doch1 = "PLAYER 1 WINS!" } else { doch1 = "PLAYER 2 WINS!" } } randomDice()
about 4 years ago · Juan Pablo Isaza
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!