Start learning free

LESSON 96 OF 414 · CONDITIONAL STATEMENTS - CHALLENGES

Employee of the Year V2 - Project in TypeScript

Practice

Two employees are up for the Employee of the Year award. Pick the more productive one and compute 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;

Build:

Mary Jane
Bonus: $50250

Rules:

  • The winner is whichever employee has the higher productivity.
  • If both have the same productivity, employee 1 (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 if/else to assign them, so both are still in scope for the prints. A tie goes to employee 1, so compare with >=.

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;

let winnerName: string, winnerSalary: number;
if (productivity1 >= productivity2) {
    winnerName = name1;
    winnerSalary = salary1;
} else {
    winnerName = name2;
    winnerSalary = salary2;
}
const bonus: number = Math.floor(winnerSalary * 15 / 100);
console.log(winnerName);
console.log("Bonus: $" + bonus);

STEP 1 OF 10
    Ctrl + Enter to check

    Employee Of The Year V2 in TypeScript

    Keep going with TypeScriptAbout 340 step-by-step lessons, from your first line of code to coding interviews. Free to start.
    Start learning free