Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

177
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda