-6

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.stack.imgur.com/52Pbd.png

Giuseppe Romeo
  • 111
  • 1
  • 2
  • 13

1 Answers1

2

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;

Gavin
  • 4,365
  • 1
  • 18
  • 27