Advertisement
Spocoman

05. Godzilla vs. Kong

Dec 16th, 2021 (edited)
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function godzillaVsKong(input) {
  2.     let budget = Number(input[0]) * 0.9;
  3.     let statist = Number(input[1]);
  4.     let dress = Number(input[2]);
  5.  
  6.     if (statist > 150) {
  7.         dress *= 0.9;
  8.     }
  9.  
  10.     budget -= statist * dress;
  11.  
  12.     if (budget >= 0) {
  13.         console.log(`Action!\nWingard starts filming with ${budget.toFixed(2)} leva left.`);
  14.     } else {
  15.         console.log(`Not enough money!\nWingard needs ${Math.abs(budget).toFixed(2)} leva more.`);
  16.     }
  17. }
  18.  
  19. Решение с тернарен оператор:
  20.  
  21. function godzillaVsKong(input) {
  22.   let budget = Number(input[0]) * 0.9;
  23.   let statist = Number(input[1]);
  24.   let dress = Number(input[2]);
  25.  
  26.   budget -= statist * (dress *= statist > 150 ? 0.9 : 1);
  27.  
  28.   console.log(
  29.     budget >= 0
  30.       ? `Action!\nWingard starts filming with ${budget.toFixed(2)} leva left.`
  31.       : `Not enough money!\nWingard needs ${Math.abs(budget).toFixed(2)} leva more.`
  32.   );
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement