This forum is now read-only. Please use our new forums! Go to forums

banner
Close banner
0 points
Submitted by Morgan Buck
over 9 years

Why doesn't this run?

The code challenge: write a piece of code that displays 10 random numbers, each between 1 and 50. If it’s above 50, it should say “high” and if it’s below it should say “low”.

    <?php
    $random= rand(1, 50);
    while ($rand >= 25)
    {echo $rand."- High</b>";}
    elseif 
    {echo $rand;}
    $count++; //increment by 1
    ?>

I keep getting an error saying: “Parse error: syntax error, unexpected ‘elseif’ (T_ELSEIF)”

Answer 543995927c82ca81ca002925

0 votes

Permalink

You are using a while! Elseif is something you should use when using an if statement before, like:

if($traffic_comes_from_left){
wait();
}
elseif($traffic_comes_from_right){
wait();
}

else { dont.wait(); }

points
Submitted by Robinvb
over 9 years

Answer 54494d3e9c4e9dda30000571

0 votes

Permalink

There are some concepts I would like to clear but first right script for you $i=1; while ($i<11) { $random= rand(1, 50); echo $random; echo '&nbsp'; if ($random >= 25) {echo $random."- High</b>";} else {echo $random;} $i++; echo '<br>'; } //increment by 1

This will run the code until the while condition is satisfied i.e. $i is less than 11 or simply you can also type $i=10; Second the increment value you are using should be defined first so it can be increased like if you have types $count = 5 then it will be kept on increasing until the loops condition is satisfied.

points
Submitted by Waqass
over 9 years