-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathif.php
67 lines (47 loc) · 1.97 KB
/
if.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<!doctype html>
<html>
<head>
<title>PHP If Statements</title>
</head>
<body>
<h1>PHP If Statements</h1>
<p>Use PHP echo and variables to output the following link information, use if statements to make sure everything outputs correctly:</p>
<?php
// **************************************************
// Do not edit this code
// Generate a random number (1, 2, or 3)
$randomNumber = ceil(rand(1,3));
// Display the random number
echo '<p>The random number is '.$randomNumber.'.</p>';
// Based on the random number PHP will define four variables and fill them with information about Codecademy, W3Schools, or MDN
// The random number is 1, so use Codecademy
if ($randomNumber == 1)
{
$linkName = 'Codecademy';
$linkURL = 'https://www.codecademy.com/';
$linkImage = '';
$linkDescription = 'Learn to code interactively, for free.';
}
// The random number is 2, so use W3Schools
elseif ($randomNumber == 2)
{
$linkName = '';
$linkURL = 'https://www.w3schools.com/';
$linkImage = 'w3schools.png';
$linkDescription = 'W3Schools is optimized for learning, testing, and training.';
}
// The random number is 3, so use MDN
else
{
$linkName = 'Mozilla Developer Network';
$linkURL = 'https://www.codecademy.com/';
$linkImage = 'mozilla.png';
$linkDescription = 'The Mozilla Developer Network (MDN) provides information about Open Web technologies.';
}
// **************************************************
// Beginning of the exercise, place all of your PHP code here
// Upload this page (or use your localhost) and refresh the page, the h2 below will change
echo '<h2>'.$linkName.'</h2>';
?>
</body>
</html>