Advertisement
Spocoman

01. Cinema

Dec 20th, 2021 (edited)
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function cinema(input) {
  2.     let screeningType = input[0]
  3.     let rows = Number(input[1])
  4.     let columns = Number(input[2])
  5.     let ticketPrice = 0;
  6.  
  7.     if (screeningType === "Premiere") {
  8.         ticketPrice = 12.00;
  9.     } else if (screeningType === "Normal") {
  10.         ticketPrice = 7.50;
  11.     } else {
  12.         ticketPrice = 5.00;
  13.     }
  14.  
  15.     console.log(`${(rows * columns * ticketPrice).toFixed(2)} leva`);
  16. }
  17.  
  18. Второ решение с тернарен оператор:
  19.  
  20. function cinema(input) {
  21.     let screeningType = input[0]
  22.     let rows = Number(input[1])
  23.     let columns = Number(input[2])
  24.    
  25.     let ticketPrice =
  26.         screeningType === "Premiere" ? 12.00 :
  27.             screeningType === "Normal" ? 7.50 : 5.00;
  28.  
  29.     console.log(`${(rows * columns * ticketPrice).toFixed(2)} leva`);
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement