OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How to read just one line from a TXT file?

  • Thread starter Thread starter Matias Sanabria
  • Start date Start date
M

Matias Sanabria

Guest
I'm creating a Wordle-like game and I need to create a dictionary in a TXT file. At the moment I'm just using a vector in my script.js file.

The idea is to have one word on each line like this:

Code:
ANGEL
APPLE
HELLO
...

I created the .txt and am reading it from my JS

Code:
import { readFile } from "fs"; 
readFile("dictionary.txt", "utf8", (err, data) => {
    if (err) {
      console.error(err);
      return;
    }
    const randomLine = lines[Math.floor(Math.random() * lines.length)];
    console.log(randomLine);
  });

<p>I'm creating a Wordle-like game and I need to create a dictionary in a TXT file. At the moment I'm just using a vector in my script.js file.</p>
<p>The idea is to have one word on each line like this:</p>
<pre><code>ANGEL
APPLE
HELLO
...
</code></pre>
<p>I created the .txt and am reading it from my JS</p>
<pre><code>import { readFile } from "fs";
readFile("dictionary.txt", "utf8", (err, data) => {
if (err) {
console.error(err);
return;
}
const randomLine = lines[Math.floor(Math.random() * lines.length)];
console.log(randomLine);
});

</code></pre>
 

Latest posts

Top