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

184
Vistas
Why does my code print this string as undefined on my window?

I'm working on code which will display log files on my computer to a window with a clickable link to access the contents of the log file. The code shown below is script.js and index.html. srcipt.js reads the files and uses a for loop to format them in html and index.html is just supposed to display the logs to the window. However whenever I press my button all it displays is the word undefined on my window and I'm not sure why.

script.js

const fs = require('fs');

var outputHTML = '';

var logdirname = '.././logs/';
    var alllogs = fs.readdirSync(logdirname, function(err, filenames) {
        if (err) {
            onError(err);
            return console.log("Error");
            }
    });

outputHTML += "<table>";
for (var i = 0; i <= alllogs.length ; i++) {
    let iPlusOne = i+1;
    outputHTML += "<tr><td>";
    outputHTML += "<a href=G:\logs\\" + alllogs[i] + ">Log File " + iPlusOne;
    outputHTML += "</a></td></tr>\n"
}
outputHTML += "</table>";
console.log(outputHTML);

index.html

<!DOCTYPE html>
<html>

<head>
    <script type="text/javascript"
        src="script.js">
    </script>
    
</head>

<body>
    <button onclick= "f()">
        Click To Access Logs
    </button>

    <div>
        <p id="text">
        </p>
    </div>
    
    <script type="text/javascript">
        

        function f() {
            
           document.getElementById("text").innerHTML = outputHTML;

        }

    </script>
</body>
</html>
about 4 years ago · Juan Pablo Isaza
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