textarea live character counting + Preview not working : <p>I am trying to get live character count + live preview of an textarea usign pure JS no Jquery, but getting some error. Here my code</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>var wpcomment = document.getElementById('text');

wpcomment.onkeyup = wpcomment.onkeypress = function(){
    document.getElementById('DrevCom').innerHTML = this.value;
}
function count()
{
  var total=document.getElementById("text").value;
  total=total.replace(/\s/g, '');
  document.getElementById("total").innerHTML="Total Characters:"+total.length;
}</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;textarea id="text" onkeyup="count();"  placeholder="Add comments:"&gt;&lt;/textarea&gt;



&lt;p id="total"&gt;Total Characters:0&lt;/p&gt;
&lt;div id="DrevCom"&gt;&lt;/div&gt;</code></pre>
</div>
</div>
</p>
