fork download
  1. <?php
  2.  
  3. // your code goes here
  4.  
  5. function tekaTekiTeko(int $batas)
  6. {
  7. if ($batas < 20) {
  8. throw new InvalidArgumentException("Parameter harus lebih besar atau sama dengan 20.");
  9. }
  10.  
  11. for ($i = 1; $i <= $batas; $i++) {
  12. $output = '';
  13.  
  14. if ($i % 2 === 0) {
  15. $output .= 'Teka';
  16. }
  17. if ($i % 3 === 0) {
  18. $output .= 'Teki';
  19. }
  20. if ($i % 5 === 0) {
  21. $output .= 'Teko';
  22. }
  23.  
  24. echo $output !== '' ? $output : $i;
  25. echo PHP_EOL;
  26. }
  27. }
  28.  
  29. // Contoh pemanggilan
  30. tekaTekiTeko(30);
  31.  
Success #stdin #stdout 0.04s 25528KB
stdin
Standard input is empty
stdout
1
Teka
Teki
Teka
Teko
TekaTeki
7
Teka
Teki
TekaTeko
11
TekaTeki
13
Teka
TekiTeko
Teka
17
TekaTeki
19
TekaTeko
Teki
Teka
23
TekaTeki
Teko
Teka
Teki
Teka
29
TekaTekiTeko