Question would be, how can I add a text file that includes a string to my js file, I want to check the repeated words in a string and keep a count in JavaScript, but I have no idea how to add text file to my js script.
My JS script is like this:
let words = "Awesome Javascript coding woohoo";
function countRepeatedWords(sentence) {
let words = sentence.split(" ");
let wordMap = {};
for (let i = 0; i < words.length; i++) {
let currentWordCount = wordMap[words[i]];
let count = currentWordCount ? currentWordCount : 0;
wordMap[words[i]] = count + 1;
}
return wordMap;
}
console.log(countRepeatedWords(words));
So I would like to add my text file (named TextFile2.txt) that contains:
"Awesome Javascript coding woohoo woohoohoho";
to then from inside my JS script and my text file string would be printed out, instead printing out:
let words = "Awesome Javascript coding woohoo";