<!--my solution-->
<html>
<head>
<meta charset="UTF-8">
<title>출력결과 - 섹션1-2 - 삼각형 판별하기</title>
</head>
<body>
<script>
function solution(a, b, c) {
// 세 변을 가지고 삼각형이 될 수 있으면 YES 아니면 NO 출력
// 삼각형은 가장 긴 변의 길이가 나머지 두 변의 합보다 크거나 같으면 안됨
// 나의 풀이 순서 일단 가장 큰 변의 길이를 찾아서 변수에 담아놓은 후 나머지 두 변의 합과 비교하기
let bigSide;
let allSide = a + b + c;
if (a > b) {
bigSide = a;
} else {
bigSide = b;
}
if (!(bigSide > c)) {
bigSide = c;
}
//bigSide - (a+b+c);
if ((allSide - bigSide) <= bigSide) {
return "NO";
} else {
return "YES";
}
}
console.log(solution(2, 5, 5));
</script>
</body>
</html>
<!--teacher's solution-->
<html>
<head>
<meta charset="UTF-8">
<title>출력결과</title>
</head>
<body>
<script>
function solution(a, b, c){
let answer="YES", max;
let tot=a+b+c;
if(a>b) max=a;
else max=b;
if(c>max) max=c;
if(tot-max<=max) answer="NO";
return answer;
}
console.log(solution(13, 33, 17));
</script>
</body>
</html>
내건 코드가 좀 길다.
if (!(bigSide > c)) {
bigSide = c;
}
쌤꺼
if(c>max) max=c;