Spocoman

02. Bonus Score

Dec 16th, 2021 (edited)
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function bonusScore(input) {
  2.     let number = Number(input[0]);
  3.     let bonus = 0;
  4.  
  5.     if (number <= 100) {
  6.         bonus = 5;
  7.     } else if (number > 1000) {
  8.         bonus = number * 0.1;
  9.     } else {
  10.         bonus = number * 0.2;
  11.     }
  12.     if (number % 2 == 0) {
  13.         bonus += 1;
  14.     } else if (number % 10 == 5) {
  15.         bonus += 2;
  16.     }
  17.     console.log(bonus);
  18.     console.log(number + bonus);
  19. }
  20.  
  21. Решение с тернарен оператор:
  22.  
  23. function bonusScore(input) {
  24.     let number = Number(input[0]);
  25.  
  26.     let bonus = number <= 100 ? 5 : number > 1000 ? number * 0.1 : number * 0.2;
  27.     bonus += number % 2 == 0 ? 1 : number % 10 == 5 ? 2 : 0;
  28.    
  29.     console.log(`${bonus}\n${number + bonus}`);
  30. }
  31.  
Add Comment
Please, Sign In to add comment