The top story

Exercise 4 of 6 in chapter 1 · 100 XP · 4 objectives checked by tests

Topics covered: ifelseBooleanComparison

Not all news is created equal: the pumpkin festival is the event of the year. Madame Lou has marked it with 'une' => true (une means front page). As for the article about the mayor's cat, Gaston has taken his name off it: he'd rather not fall out with the mayor.

Your mission

  1. In the loop, when an article's une key is true, open it with <article class="article une"> and add the banner <p class="bandeau">Top story</p> before its title.
  2. Otherwise, keep <article class="article">, with no banner.
  3. When the author is an empty string, print <p class="auteur">By the newsroom</p> instead.

Reminder

if runs a block only if its condition is true, and else takes over otherwise. A boolean is either true or false. To compare, === checks that two values are equal and of the same type, unlike the more lenient ==.

When an if/else only picks between two values, PHP has a short form, the ternary operator: condition ? valueIfTrue : valueIfFalse. For example, $classe = $article['une'] ? 'article une' : 'article';. Stick with the if as soon as there's more than one thing to do, as here with the banner.