머쓱이네 옷가게는 10만 원 이상 사면 5%, 30만 원 이상 사면 10%, 50만 원 이상 사면 20%를 할인해줍니다.
구매한 옷의 가격price
가 주어질 때, 지불해야 할 금액을 return 하도록 solution 함수를 완성해 보세요.
price
≤ 1,000,000price
는 10원 단위로(1의 자리가 0) 주어집니다.price | result |
---|---|
150000 | 142500 |
580000 | 464000 |
function solution (price) {
let answer = 0
if (price >= 100000 && price < 300000) {
answer = parseInt(price * 0.95)
} else if (price >= 300000 && price < 500000) {
answer = parseInt(price * 0.9)
} else if (price >= 500000) {
answer = parseInt(price * 0.8)
} else answer = parseInt(price)
return answer
}