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

175
Views
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
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!