I would like to know if there is a possibility to get the text content of a file and transform it in a string or array, so that I can get random words from it.
I have to solve the following coding challenge in Javascript:
**
A program that randomly displays words from a text.
1.) Read a text file with a lot of content and randomly output a certain number of words
Example:
*enter how many words you want: 5
Output: anything acceptance shall and EVEN*
**
I manage to write a code that displays a text on the page, but I can't think of a solution to get the content and get random words from it.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Random Tweet Generator</title>
<input type="file" name="inputfile" id="inputfile">
<br>
<pre id="output"></pre>
<style>
</style>
</head>
<body>
<h1>Random Tweet Generator</h1>
<script>
document.getElementById('inputfile')
.addEventListener('change', function() {
let fr=new FileReader();
fr.onload=function(){
document.getElementById('output')
.textContent=fr.result;
}
fr.readAsText(this.files[0]);
})
</script>
</body>
</html>