karlakmkj

Tenary operator

Sep 17th, 2021
723
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. namespace Codecademy;
  3.  
  4. // tenary operator to replace if-else stm
  5. function ternaryCheckout($item){
  6.   return $item <= 12 ? "express lane" : "regular lane";
  7. }
  8.  
  9. function ternaryVote($age){
  10.   return $age >=18 ? "yes" : "no";
  11. }
  12.  
  13.  
  14. echo ternaryCheckout(30);
  15. echo "\n";
  16. echo ternaryCheckout(1);
  17. echo "\n";
  18. echo ternaryVote(18);
  19. echo "\n";
  20. echo ternaryVote(5);
RAW Paste Data