Измените свои input
s следующим образом
Side 1: <input type="text" id="aInput"><br>
Side 2: <input type="text" id="bInput"><br>
Side 3: <input type="text" id="cInput"><br>
Length: <input type="text" id="lengthInput"><br>
В настоящее время вы даете элементам input
2 идентификатора, но вам нужно установить тип текста, а затем настроить id.
Также необходимо переместить переменную tVol
в prismVolume()
:
/* Function triangleArea() is called by prismVolume(), which is called by
doInputOutput().
* doInputOutput() is the only function that takes use input and outputs result to a div.
*/
function doInputOutput() {
var a = parseFloat(document.getElementById("aInput").value);
var b = parseFloat(document.getElementById("bInput").value);
var c = parseFloat(document.getElementById("cInput").value);
var length = parseFloat(document.getElementById("lengthInput").value);
var volume = prismVolume(a, b, c, length);
document.getElementById("volDiv").innerHTML = volume;
}
function prismVolume(a, b, c, length) {
var s = (a + b + c) / 2;
var area = Math.sqrt(s * (s - a) * (s - b) * (s - c));
var tVol = area * length;
// Rounds to 2 places.
var digits = 2;
var mult = Math.pow(10, digits);
var volume = Math.round(tVol * mult) / mult;
return volume;
}
function triangleArea(a, b, c) {
var s = (a + b + c) / 2;
var area = Math.sqrt(s * (s - a) * (s - b) * (s - c));
return area;
}
This program will compute the volume of a triangular prism.<br />
Please enter the following triangular prism measurements:<br />
Side 1: <input type="text" id="aInput" /><br />
Side 2: <input type="text" id="bInput" /><br />
Side 3: <input type="text" id="cInput" /><br />
Length: <input type="text" id="lengthInput" /><br />
<button type="button" onclick="doInputOutput()">Volume</button>
<div id="volDiv"></div>