Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

220
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!