I am having tough time with this code that should read a microsoft word's document file and output the number of words into a div element.
I tried everything and the code outputs the number of word into console but not in the div. Please help me here. Thank you so much
Here is my html page
<div id="demo"></div>
<script src="script.js"></script>
Here is my script.js
// Installed mammoth using npm
var mammoth = require("mammoth");
// I have a doc file with some sample content
var docxFile = "file.docx";
// Below is my function to count the number of words on that document
function WordCount(str) {
return str.split(" ").length;
}
// Below is my Mammoth module extracts the text from my docx file and the function above counts the word for me and displays on the console. I want to be able to display it on my HTML page.
mammoth.extractRawText({path: docxFile})
.then(function(result){
var text = result.value; // The raw text
console.log("Word Count: " + WordCount(text));
// Below is what I want to do. but its not working.
document.getElementById('demo').innerHTML = (WordCount(text));
})
.done();
The above code should display the number of words from the file.docx into the div element ID "demo" but its not doing so. please help