• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

149
Views
por qué no funciona mi .innerHTML, juego javascript

Juro que puedo hacer esto y debe ser solo un error de la máquina. Tengo lo mismo trabajando en más programas pero dentro de un método. Simplemente estaba haciendo frente al código de trabajo de otra persona. No puedo actualizar la puntuación de 0 a 1. ¿Alguien puede echar un vistazo? debe ser el error de lógica más pequeño o algo así. Sí, estoy llamando a mi css y js. Gracias por adelantado

 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Clicker</title> <link rel="stylesheet" href="styles.css"> </head> <body> <script src="game.js"></script> <h1>CLICKER</h1> <p id="score">Score: 0</p> <img id="algae" src="/images/algaepng.png" alt="Image"> </body> </html>

DE JUEGO.JS

 let score = 0; score = score +1; document.getElementById('score').innerHTML = "Score: " + score;
almost 3 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Su código javascript se ejecuta antes que el código HTML
Solución 1: declarar el guión en la cabecera con la palabra diferir

 let score = 0; score = score + 1; document.getElementById('score').innerHTML = "Score: " + score;
 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Clicker</title> <link rel="stylesheet" href="styles.css" /> <script src="game.js" defer></script> </head> <body> <h1>CLICKER</h1> <p id="score">Score: 0</p> </body> </html>

Solución 2: declare su javascript al final del cuerpo

 let score = 0; score = score + 1; document.getElementById('score').innerHTML = "Score: " + score;
 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Clicker</title> <link rel="stylesheet" href="styles.css" /> </head> <body> <h1>CLICKER</h1> <p id="score">Score: 0</p> <script src="game.js"></script> </body> </html>

almost 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error