Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP PHP Arrays and Control Structures PHP Loops Ping Pong

Workspaces Not working

In this workspasces when I run it I get: PHP Parse error: syntax error, unexpected ';' in /home/treehouse/workspace/ping_p ong.php on line 18 But what am I doing wrong

<?php $player1 = 0; $player2 = 0; $round = 0;

//var_dump(abs($player1-$player2)); //var_dump($player2-$player1); /* TO WIN A WLAYER MUST REACH 11 AND BE HIGHER THAN THE OTHER BY 2 WHILE NOT MET RANDOMLY INCREMETN ON SCORE EACH ROUND

*/

while ((abs($player1 - $player2))<2 || ($player1 < 11 && $player2 < 11)) { $round++; echo "<h2>Round $round</h2>\n"; if (rand(0,1) { $player1++; } else { $player2++; } echo "Player1 = $player1<br />\n"; echo "Player2 = $player2<br />\n"; } echo "<h1>"; if ($player1 > $player 2) { echo "Player 1"; } else { echo "Player 2"; } echo " is the winner after $round rounds!</h1>\n";

?>

1 Answer

Same issue I had this means you do not have something closed in your code. Looking at your code it looks like you forgot to put another parenthesis around the if statment after rand()

if(rand(0,1)){
    $player1++;
  } else {
    $player2++;
  }