Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

228
Visualizações
The prompt part works but not the if-else conditions inside the function. What did I do wrong?

I'm trying to display an alert that says what kind of triangle it is with the inputs from the prompt but the if-else conditions won't work when I put it inside a function. If it isn't inside a function it works fine but it is a requirement to put it inside.

tried this and only the prompt part works

<!DOCTYPE html>
<html>
<body>
    <script>
        var a = prompt("Enter the length of side A: ");
        var b = prompt("Enter the length of side B: ");
        var c = prompt("Enter the length of side C: ");
        
        function determineTriangle(a, b, c) {
        if (a == b && b == c){
            window.alert("The triangle is EQUILATERAL")
        }
        
        else if (a == b || b == c || c == a){
            window.alert("The triangle is ISOSCELES");
        }
        
        else{
            window.alert("The triangle is SCALENE");
        }
        }
    </script>
</body>
</html>

I've encountered a new problem. I need to use the isNan() function to check if the input is a number and I added this part

<!DOCTYPE html>
<html>
<body>
    <script>
        var a = prompt("Enter the length of side A: ");
        var b = prompt("Enter the length of side B: ");
        var c = prompt("Enter the length of side C: ");
        
        if (isNan(a)) {
            window.alert("You did not enter a number")
        }
        else {
        determineTriangle(a, b, c)
        }
        
        if (isNan(b)) {
            window.alert("You did not enter a number")
        }
        else {
        determineTriangle(a, b, c)
        }
        
        if (isNan(c)) {
            window.alert("You did not enter a number")
        }
        else {
        determineTriangle(a, b, c)
        }

        function determineTriangle(a, b, c) {
        if (a == b && b == c){
            window.alert("The triangle is EQUILATERAL")
        }
        
        else if (a == b || b == c || c == a){
            window.alert("The triangle is ISOSCELES");
        }
        
        else{
            window.alert("The triangle is SCALENE");
        }
        }
        determineTriangle(a, b, c);
    </script>
</body>
</html>

and It doesn't work again.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda