Powered by Blogger.

FETCHING RANDOM LINE FROM TEXT FILE


Assuming that the text file at Dictionary.txt and your HTML file has a div with an id value of “word”
success: function (data) {
 //console.log(data);
 wordslist = data.toString().split("\n");
 randomLineIndex = Math.floor( Math.random() * wordslist.length );
 console.log(randomLineIndex);
 word = wordslist[randomLineIndex];
 $(".word").append("<h2>"+word+"</h2>");
 }

No comments