Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

JS mathematic, live counting

I am trying to make live mathematic calculation based on characters count.
Counting of characters works, but other variables like dividing this sum by 1500 or multiplication of this sum by 30, doesn’t work. Console tell’s me nothing, but in text I am getting "NaN".

I am beginner in mathematics in JS and i don’t see why it does not works.
All sources in google tells me that it is good writed.

I am attaching screen of html and code under this text.
On screen is pasted exactly 3000 letters.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Please help <3

enter image description here

<script type="text/javascript">
function count()
{
  var total=document.getElementById("text").value;
  total=total.replace(/\s/g, '');
  document.getElementById("total").innerHTML="total: <span>"+total.length+"</span>";

    var divided=total.lenght/1500;
    document.getElementById("divided").innerHTML="divided: <span>"+divided+"</span>";

    var price=divided*30;
    document.getElementById("pricing").innerHTML="price: <span>"+price+"</span>";
}
</script>


    

    <div id="pricing-counter">
<p id="total">total:<span>0</span></p>
<p id="divided">divided:<span>0</span></p>
<p id="pricing">price:<span>0</span></p>
    </div>

>Solution :

You had a typo in the line where you set divided

function count()
{
  var total=document.getElementById("text").value;
  total=total.replace(/\s/g, '');
  document.getElementById("total").innerHTML="total: <span>"+total.length+"</span>";

    var divided=total.length/1500; // Typo corrected
    document.getElementById("divided").innerHTML="divided: <span>"+divided+"</span>";

    var price=divided*30;
    document.getElementById("pricing").innerHTML="price: <span>"+price+"</span>";
}
 <div id="pricing-counter">
<input id="text"></input>
<button onclick="count()">Count</button>
<p id="total">total:<span>0</span></p>
<p id="divided">divided:<span>0</span></p>
<p id="pricing">price:<span>0</span></p>
    </div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading