I am doing a php lab and one of my tasks is to: do a “rick-roll” for a link. You are to output a link ( tag) that contains cat image ( tag). 50% of the time, your code will have the link go to the correct video, the other 50% of the time the link will go to a video of Rick Ashley’s song “Never Going to Give You Up” This task will require an if-else statement.
I know that using an if/else statement using the mt_rand(0,1) function will give me a 50% chance since it will either be 1 or 0 but I don't know how to make the links go to the correct video or Rick Astley's song. Here is my code:
<!-- TASK 2 -- Write your PHP code in in the space provided below. -->
<div class="task">
<h2> Task 2: Rick Roll </h2>
<p> Click for a funny cat video! </p>
<? php
if (mt_rand(0,1) == 0) {
header('https://www.youtube.com/watch?v=hY7m5jjJ9mM');
exit;
} else {
header('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
exit;
}
<a href="https://www.youtube.com/watch?v=hY7m5jjJ9mM">
<img src="https://images.pexels.com/photos/104827/cat-pet-animal-domestic-104827.jpeg?h=350&auto=compress&cs=tinysrgb" alt="cute cat" width="250" height="250":>
</a>
<!--?php
/* Task 2: Put your code here */
?-->
</div>