[FAQ] Common Problems #ReadMe


#1

So i noticed many people are having difficulties with this exercise. Hopefully this will help!


1st Common mistake:
Check your while loop syntax is correct:

while (condition) {
}

2nd check you have a ; at the end of every code statement like this:

while (condition) {
echo "Hey"; // You need a semi colon here
}

The 3rd common mistake is that you are meant to echo the statement with <p> tags like the instructions say. It should be:

echo "<p>The loop is running.</p>";

Not

echo "The loop is running.";

This is very important and is why some of you are getting the error to do with p:first-child


4th common mistake, make sure you don't have an infinite loop as it will crash your browser!

This is bad as the condition never changes:

$condition =  true;
while ($condition) {
 echo "Hey";
}

You need to make sure that the condition being evaluated in the while loop is changed within the loop. Like so:

$condition =  true; // setting $condition to true (it is a Boolean)
while ($condition) { // Runs when $condition (see below tip)
 echo "Hey"; // echo's with a semi colon at the end!
$condition = false; // changes $condition so the loop doesnt run forever.
}

In your while loop you only need $condition not $condition = true because $condition is a Boolean so is true or false, therefore when $condition is set to true the loop runs because the condition evaluates to true, and when it is set to false the loop doesn't run.


5th Check your spelling and capitalization, the correction tests are case sensitive so
echo "The Loop is Running"; would not work, because of the Capitals on "Loop" & "Running".


Hope these tips help!
Please create a new topic if you require any more help, or post below for clarification.

Thanks,
Alex


#2

#3

3 posts were split to a new topic: Not passing due to space


#5