Last active
January 16, 2018 07:47
-
-
Save goastoman/b62f822b18f9af4d773cfad8ab7a6d9d to your computer and use it in GitHub Desktop.
Площадь треугольника по трем сторонам с проверками
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const getTriangleArea = (a, b, c) => { | |
if (a > 0 && b > 0 && c > 0) { | |
const p = (a + b + c) / 2; | |
console.log(p); | |
const area = Math.sqrt(p * (p - a) * (p - b) * (p - c)); | |
console.log(area); | |
if (isNaN(area)) { | |
return "Такого треугольника не существует"; | |
} else if (area === 0) { | |
return "Невозможно вычислить ( = 0)"; | |
} else return ("Площадь треугольника = " + area); | |
} else if (a === 0 || b === 0 || c === 0) { | |
return "Одна из сторон = 0. Это не треугольник ;)"; | |
} else return "Введите корректные данные"; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment