Lab 10, Part 2 -------------- This was the exercise in which you had to work out whether one date was before, after or the same as another. I graded it generously - e.g. I was more concerned that it worked, than worrying whether the if's were as elegant as they could be. Hence, most of you scored 10 out of 10. Many of you clearly did not TEST your work on enough pieces of TEST DATA!!!!! In grading, I ran it more than 10 times - which was still not very many. I doubt you came even close to running it that many times. The student who omitted the month of May might have detected his error if he had tested his program more. The student who was using $day_a but in one part used $day_1 might have detected this if he had ensured that every path through his program was tested. The student who used = instead of == might have found this if he had tested more. If you didn't score 10 out of 10, here are some observations: You scored 0, as usual, if you submitted work that contained a compile-time error (syntax error). The main thing was to use the array of months. A few of you didn't realise that if you ask this: if ( $month_a < $month_b ) then you are asking whether one month comes alphabetically before another, which isn't what we want. It will say, for example, that March comes AFTER April, which it does in the alphabet but not in the calendar. So you have to find the POSITIONS of the months in the array. Here's the code for finding their positions: $months = array('January', 'February',...); $counter = 0; $month_a_index = 0; $month_b_index = 0; foreach ( $months as $month ) { if ( $month == $month_a ) { $month_a_index = $counter; } if ( $month == $month_b ) { $month_b_index = $counter; } $counter++; } Several of you then made a mess of the ifs. This is disappointing at this stage of the year. It was quite simple: if ( ($year_a < $year_b) || ( ($year_a == $year_b) && ($month_a_index < $month_b_index) ) || ( ($year_a == $year_b) && ($month_a_index == $month_b_index) && ($day_a < $day_b)) ) { $answer = "before"; } elseif ( ($day_a == $day_b) && ($month_a_index == $month_b_index) && ($year_a == $year_b) ) { $answer = "same"; } else { $answer = "after"; } Ask us in the next lab to explain any part of the above that doesn't make sense to you.