You have used if statements in PHP and (like this one) in JavaScript:

if (window.document.body('colourTest').style.backgroundColor=='yellow') {
    window.document.body('colourTest').style.backgroundColor='red'
}

You have also added an else.  There are other structures which do similar things.  They have a condition and if that condition is met they do something.  In JavaScript and PHP the condition is the bit inside the normal brackets.  Conditions are either true or false.  As mentioned with regards to loops a true or false can also be provided by running a function.  That function then returns a false if it fails to run (anything other than a false is treated as true).  In JavaScript you could do this:

if(document.getElementById('container')){

If an element with an id of container exists the if receives a true but if it is not in the page a false is returned by getElementById (meaning I have failed to find it).