aquí está el código
<h1>Timeworn Kumbhiraskin Maps</h1> <label for="room">What chamber did you reach?</label> <select id="room"> <option value="none">No portal</option> <option value="first">First Chamber</option> <option value="second">Second Chamber</option> <option value="third">Third Chamber</option> <option value="fourth">Fourth Chamber</option> <option value="fifth">Final Chamber</option> </select> <ul id="percentages"> <li id="np">No portal: </li> <li id="firstC">First Chamber: </li> <li id="secondC">Second Chamber: </li> <li id="thirdC">Third Chamber: </li> <li id="fourthC">Fourth Chamber:</li> <li id="fifthC">Final Chamber: </li> </ul> </body> </html> var totalMaps = 0; var pPortal = 0; var pFirst = 0; var pSecond = 0; var pThird = 0; var pFourth = 0; var pFifth = 0; window.onload = function(){ document.getElementById("np").value += string(pPortal); document.getElementById("firstC").value += string(pFirst); document.getElementById("secondC").value += string(pSecond); document.getElementById("thirdC").value += string(pThird); document.getElementById("fourthC").value += string(pFourth); document.getElementById("fifthC").value += string(pFifth); }Básicamente, solo estoy teniendo problemas con el javascript. Quiero mostrar las variables de javascript en la lista, pero no se muestra. ¿Alguna ayuda? ¿Estoy haciendo algo mal? Probé algunos métodos diferentes y busqué en línea, pero parece que nadie tiene la respuesta que estoy buscando.
Si desea convertir una variable en una cadena, tiene para usted la función String() (sensible a mayúsculas y minúsculas). También te perdiste la parte que decía innerHTML. Esto es trabajo para mí
<body> <ul id="percentages"> <li id="np">No portal: </li> <li id="firstC">First Chamber: </li> <li id="secondC">Second Chamber: </li> <li id="thirdC">Third Chamber: </li> <li id="fourthC">Fourth Chamber:</li> <li id="fifthC">Final Chamber: </li> </ul> </body> <style> body {padding: 0.5rem 1rem;} </style> <script> let totalMaps = 0; let pPortal = 0; let pFirst = 0; let pSecond = 0; let pThird = 0; let pFourth = 0; let pFifth = 0; window.onload = function(){ document.getElementById("np").innerHTML += String(pPortal); document.getElementById("firstC").innerHTML += String(pFirst); document.getElementById("secondC").innerHTML += String(pSecond); document.getElementById("thirdC").innerHTML += String(pThird); document.getElementById("fourthC").innerHTML += String(pFourth); document.getElementById("fifthC").innerHTML += String(pFifth); } </script>Prueba esto
document.getElementById('np').innerHTML += pPortal;... etc. El operador JS + convierte automáticamente su tipo de número en una cadena en este caso.