Search code examples
javascripthtmloperations

operations with javascript in html document


I want the label with id="risultato" display the area of triangle,I tried to make this,but when I pressed button "risultato:" the risult is NaN,why? Thanks lots

code: https://i.sstatic.net/52Pbd.png


Solution

  • You are getting NaN because of this:

    var altezza = document.getElementById('altezza');
    var base = document.getElementById('base');
    (base*altezza/2)
    

    getElementById() does exactly that - gets the element. You just need to get the value from the element e.g. var altezza = document.getElementById('altezza').value;