Problem
- Salary will be an integer, and bonus a boolean.
- salary는 정수, bonus는 boolean 값이다.
- If bonus is true, the salary should be multiplied by 10.
- bonus가 true라면, salary에 10을 곱한다.
- If bonus is false, the fatcat did not make enough money and must receive only his stated salary.
- bonus가 false라면, 명시된 salary를 받는다.
- Return the total figure the individual will receive as a string prefixed with ‘$’.
Solution 01
function bonusTime(salary, bonus) {
if (bonus === true) {
return `$${salary * 10}`;
} else {
return `$${salary}`;
}
}
bonusTime(4400, true); // $44000
bonusTime(4400, false); // $4400
Solution 02
function bonusTime(salary, bonus) {
return bonus ? `$${salary * 10}` : `$${salary}`;
}
bonusTime(4400, true); // $44000
bonusTime(4400, false); // $4400
Solution 03
function bonusTime(salary, bonus) {
return '$' + salary * (bonus ? 10 : 1);
}
bonusTime(4400, true); // $44000
bonusTime(4400, false); // $4400