Testing if a value is empty with variable.length

I had a problem while coding a problem to calculate the area of a triangle given 3 sides, when the inputs are empty i want my if to make a alert and my variables assume a given value, but seems my programm just ignores the if:

function calcular(){
var lado1 = window.document.getElementById('lado1')
var lado2 = window.document.getElementById('lado2')
var lado3 = window.document.getElementById('lado3')
var l1 = Number(lado1.value)
var l2 = Number(lado2.value)
var l3 = Number(lado3.value)
if (lado1.length === 0 && lado2.length === 0 && lado3.length === 0) {
window.alert("Um ou mais campos vazios, considerando valores 5, 6 e 7.")
l1 = 5
l2 = 6
l3 = 7    
} 
var semp = (l1 + l2 + l3)/2
var area = Math.sqrt(semp*((semp-l1)*(semp-l2)*(semp-l3)))
answer.innerHTML = `A área do triângulo dado é de <strong>${area}</strong>!`
}

It works fine when i give any value on the inputs. Anyone can see the problem?



Read more here: https://stackoverflow.com/questions/68461315/testing-if-a-value-is-empty-with-variable-length

Content Attribution

This content was originally published by Ragazzoleo at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: