mercredi 6 février 2019

Trying to make if, elseif, else statement for time and when to eat using military clock format

Whenever I put in the number 12 or 16, for example, it will not say "It's time for lunch" or "It's time for dinner." It will always say "It's time for breakfast"

I've tried putting quotes around the numbers, I've tried looking at my greater than, less than, etc. signs, and it looks like that is not the problem i think..

    <?php

    $time = 4;

   if(($time >= 4) || ($time <= 11))
   {
   echo "It's time for breakfast";
   } 
   elseif(($time >= 12) || ($time <= 15))
   {
   echo "It's time for lunch";
   }
   else 
   {
   echo "It's time for dinner";
   }
   ?>

I want it to run so when I make 4 - 11 in $time it will echo "It's time for breakfast." I want from 12 - 15 in $time to echo "It's time for lunch." All other numbers should print It's time for dinner.

Aucun commentaire:

Enregistrer un commentaire