Where is the error in my Conditional Statement (PHP)? -
the challenge is:
- if n odd, print "weird".
- if n , in inclusive range of 2 5, print "not weird".
- if n , in inclusive range of 6 20, print "weird".
- if n , greater 20, print "not weird".
and code is:
<?php $n=5; if($n%2==0 && $n>20){ echo "not weird"; }else{ echo "weird"; } ?>
and problem is:
when rut locally it's okay. when submit hackerrank fails test when comes $n=5;
case. have problems in conditional according challenge?
<?php $n=5; if($n%2==1){ echo 'weird'; }else{ if($n >= 2 && $n <= 5){ echo 'not weird'; }elseif($n > 5 && $n <= 20){ echo 'weird'; }else{ echo 'not weird'; } } ?>
Comments
Post a Comment