Three employees compete for the award. Use a chained if / else if / else to pick the most productive one and print their 15% bonus.
You start with:
const name1: string = "John Doe";
const productivity1: number = 83;
const salary1: number = 135000;
const name2: string = "Mary Jane";
const productivity2: number = 133;
const salary2: number = 335000;
const name3: string = "Bob Smith";
const productivity3: number = 97;
const salary3: number = 210000;
Build:
Mary Jane Bonus: $50250
Rules:
- The winner is whichever of the three employees has the highest productivity.
- If two or more employees share the highest productivity, the one listed first wins.
- The winner's bonus is 15% of their salary, rounded down to a whole number.
- Print the winner's name on the first line, then
"Bonus: $<amount>"on the second.
Declare
let winnerName: string, winnerSalary: number; before the if, then use an if / else if / else chain to assign them, so both are still in scope for the prints. Employee 1 wins when its productivity is at least that of both others; if not, employee 2 wins when it is at least employee 3's; otherwise employee 3 wins.
Use
Math.floor to round the 15% down to a whole number: const bonus: number = Math.floor(winnerSalary * 15 / 100);
+ turns the number into text: console.log("Bonus: $" + bonus);
const name1: string = "John Doe";
const productivity1: number = 83;
const salary1: number = 135000;
const name2: string = "Mary Jane";
const productivity2: number = 133;
const salary2: number = 335000;
const name3: string = "Bob Smith";
const productivity3: number = 97;
const salary3: number = 210000;
let winnerName: string, winnerSalary: number;
if (productivity1 >= productivity2 && productivity1 >= productivity3) {
winnerName = name1;
winnerSalary = salary1;
} else if (productivity2 >= productivity3) {
winnerName = name2;
winnerSalary = salary2;
} else {
winnerName = name3;
winnerSalary = salary3;
}
const bonus: number = Math.floor(winnerSalary * 15 / 100);
console.log(winnerName);
console.log("Bonus: $" + bonus);
Free plan: 30 tutor messages. Premium is unlimited.
Saved
Ctrl + Enter to check
