Skip to content

Commit

Permalink
Fix the zero calculation in Pythagorean Theorem Calculator (#1828)
Browse files Browse the repository at this point in the history
  • Loading branch information
srilekha279 authored Aug 10, 2024
1 parent e740a60 commit 5973e44
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Calculators/Pythagorean-Theorem-Calculator/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ function calculate() {
var sideA = parseFloat(document.getElementById('sideA').value);
var sideB = parseFloat(document.getElementById('sideB').value);

if (isNaN(sideA) || isNaN(sideB)) {
alert("Please enter valid numerical values for side A and side B.");
if (isNaN(sideA) || isNaN(sideB) || sideA <= 0 || sideB <= 0) {
alert("It looks like one or both of your inputs are missing or not positive. Please enter positive values for both sides.");
return;
}

var sideC = Math.sqrt(Math.pow(sideA, 2) + Math.pow(sideB, 2));

document.getElementById('result').innerHTML = "The length of side C is: " + sideC.toFixed(2);
}
}

0 comments on commit 5973e44

Please sign in to comment.