Hago una consulta más porque cuando pongo las operaciones dentro de una función el resultado cambia y deja de ser correcto, estoy haciendo algo mal?:
Código HTML:
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<label for="D1">Monthly online conversations with customers</label>
<input type="number" name="D1" id="D1"></br>
<label for="D2">Montly cost of online support</label>
<input type="number" name="D2" id="D2"></br>
<label for="D3">Monthly phone conversations with customers</label>
<input type="number" name="D3" id="D3"></br>
<label for="D4">Montly cost of phone support</label>
<input type="number" name="D4" id="D4"></br>
<label for="result">Result</label>
<input type="text" name="result" id="result">
<button onclick="calculate();">Calculate</button>
</body>
<script type="text/javascript">
function calculate (){
var D1 = document.getElementById('D1').value;
var D2 = document.getElementById('D2').value;
var D3 = document.getElementById('D3').value;
var D4 = document.getElementById('D4').value;
var E6 = D1 / D1 * D1 * 0.3 + D1 * 0.7 * 0.15 + (D4/D3) * D3 * 0.5 + D3 * 0.5 * 0.3;
var result;
if(D2 > 0){
if(D4>0){
result = E6/(D4+D2)
}else{
result = (D1*0.6+D3*0.4)/(D1+D3)
}
}else{
result = (D1*0.6+D3*0.4)/(D1+D3)
}
result = 1 - result;
var s = Math.round(result * 100);
document.getElementById('result').value = s+"%";
console.log(s + "%");
};
</script>