Here is what I did for Pursue 4:
//Create some css styles
.red {color:red;}
.yellow {color:yellow;}
.green {color:green;}
.blue {color:blue;}
//Alter the switch statement so that each case assigns values to some new variables, and then concatenates them to a new variable, along with some html to apply the css class to the print output at the end
//Validate the color
switch ($_POST['color']) {
case 'red':
$color_type = 'primary';
$color_selected ='red';
$css_class = '<span class="red">' . "$color_selected" . '</span>'. ',';
break;
case 'yellow':
$color_type = 'primary';
$color_selected ='yellow';
$css_class = '<span class="yellow">' . "$color_selected" . '</span>' . ',';
break;
case 'blue':
$color_type = 'primary';
$color_selected ='blue';
$css_class = '<span class="blue">' . "$color_selected" . '</span>' . ',';
break;
case 'green':
$color_type = 'secondary';
$color_selected ='green';
$css_class = '<span class="green">' . "$color_selected" . '</span>'. ',';
break;
default:
print '<p class="error">Please select your favourite colour.</p>'. ',';
$okay = FALSE;
break;
} //end of switch
//Then alter the print output to include the new variable
//If there are no errors, print a success message:
if ($okay) {
print '<p>You have been successfully registered (but not really).</p>';
print "<p>You will turn $age this year";
print "<p>Your selected color, $css_class is a $color_type color.</p>";
}
I concatenated a comma onto the end of the $css_class variable cos I am a punctuation nerd (I even worried whether to put it inside or outside the span!).
This seems to work well, but I would be grateful for any comments.