1 00:00:00,810 --> 00:00:03,380 Fabulous work learning all about conditionals. 2 00:00:03,380 --> 00:00:04,220 In this section, 3 00:00:04,220 --> 00:00:08,620 we covered the many different operators needed to create descriptive conditionals 4 00:00:08,620 --> 00:00:13,690 including comparison operators, negation operators, and logical operators. 5 00:00:13,690 --> 00:00:18,540 We use those conditionals to create nested and combine if statements, and we explored 6 00:00:18,540 --> 00:00:23,680 the use of a switch statement to compare a single expression to multiple values. 7 00:00:23,680 --> 00:00:26,710 Let's recap what you've learned by creating a program for 8 00:00:26,710 --> 00:00:30,640 messaging a student based on the grade level and final grade average. 9 00:00:32,390 --> 00:00:35,726 Let's create a new file named school.php. 10 00:00:41,040 --> 00:00:43,234 Again start with our php tags and 11 00:00:43,234 --> 00:00:47,530 we're ready to map out what we're going to be doing. 12 00:00:47,530 --> 00:00:49,620 So let's start with comments. 13 00:00:49,620 --> 00:00:52,975 I'll add these in the teacher's notes so you don't have to type everything. 14 00:00:52,975 --> 00:00:55,987 If student's class average is less than 70%, 15 00:00:55,987 --> 00:00:59,859 we're going to send a message that says, dear Alena Holligan, 16 00:00:59,859 --> 00:01:03,961 we look forward to seeing you at summer school beginning July 1st. 17 00:01:03,961 --> 00:01:07,621 If the student's class average is greater than or equal to 70, 18 00:01:07,621 --> 00:01:10,547 and the current grade is 9, the message will read, 19 00:01:10,547 --> 00:01:14,790 congratulations on completing your freshman year in High School! 20 00:01:14,790 --> 00:01:18,973 We'll see you on September 1st for the start of your sophomore year! 21 00:01:18,973 --> 00:01:22,934 If the student's class average is greater than or equal to 70% and 22 00:01:22,934 --> 00:01:25,869 the current grade is 10, the message will read, 23 00:01:25,869 --> 00:01:29,700 congratulations on completing your sophomore year. 24 00:01:29,700 --> 00:01:31,312 And if the current grade is 11, 25 00:01:31,312 --> 00:01:35,130 congratulations on completing your junior year. 26 00:01:35,130 --> 00:01:37,640 And finally, if the current grade is 12, 27 00:01:37,640 --> 00:01:40,400 congratulations you've graduated high school. 28 00:01:40,400 --> 00:01:42,530 Don't forget to come back and visit. 29 00:01:42,530 --> 00:01:45,703 The variables we need are first name as a string, 30 00:01:49,395 --> 00:01:55,203 Last name, Also as a string. 31 00:01:55,203 --> 00:01:59,079 Current grade, As an integer. 32 00:02:01,501 --> 00:02:03,198 And our final average. 33 00:02:05,499 --> 00:02:07,560 Also as an integer. 34 00:02:07,560 --> 00:02:09,620 Then we'll need a variable for our message body. 35 00:02:13,560 --> 00:02:14,840 This will be a string as well. 36 00:02:15,840 --> 00:02:18,720 Let's start with a check to make sure that we have the values for 37 00:02:18,720 --> 00:02:20,820 the required variables. 38 00:02:20,820 --> 00:02:25,147 If not firstName or 39 00:02:25,147 --> 00:02:28,665 not lastName, 40 00:02:32,450 --> 00:02:37,660 We want to echo, Please enter a student name. 41 00:02:39,230 --> 00:02:40,072 Let's run our script. 42 00:02:46,384 --> 00:02:49,651 We see, Please enter a student name, because our firstName and 43 00:02:49,651 --> 00:02:53,560 lastName variables have an empty string assigned to them. 44 00:02:53,560 --> 00:02:55,324 Great, let's add Alena Holligan. 45 00:03:01,335 --> 00:03:06,958 The next thing we want to do is make sure that the current grade is between 9 and 46 00:03:06,958 --> 00:03:09,303 12 for high school students. 47 00:03:09,303 --> 00:03:12,959 So we'll add, elseif, 48 00:03:12,959 --> 00:03:18,010 our current grade is less than 9, 49 00:03:18,010 --> 00:03:24,293 or our current grade is greater than 12. 50 00:03:28,732 --> 00:03:33,387 This is only for high school students. 51 00:03:36,248 --> 00:03:43,355 Please enter a grade between 9 and 12. 52 00:03:43,355 --> 00:03:45,270 Let's run the script again. 53 00:03:45,270 --> 00:03:48,100 Now we see that we need a grade between 9 and 12. 54 00:03:48,100 --> 00:03:50,135 Let's change our current grade 9. 55 00:03:52,040 --> 00:03:56,261 Next we're ready to show a message for our students based on grade level and 56 00:03:56,261 --> 00:03:57,536 final grade average. 57 00:03:57,536 --> 00:04:00,786 So I'm going to put this next section within an else block, 58 00:04:00,786 --> 00:04:02,356 that displays the message. 59 00:04:06,057 --> 00:04:11,645 Echo "Dear firstName lastName, 60 00:04:11,645 --> 00:04:18,201 a newline character" and end the line. 61 00:04:18,201 --> 00:04:23,160 Then we're also going to echo our messageBody. 62 00:04:25,420 --> 00:04:29,112 I use double quotes so the variables are expanded. 63 00:04:29,112 --> 00:04:32,040 Now we're ready to set our message body. 64 00:04:32,040 --> 00:04:37,197 Within the else block, we add if 65 00:04:37,197 --> 00:04:42,930 finalAverage is less than .70, 66 00:04:47,021 --> 00:04:52,316 Our messageBody is going to equal our summer message. 67 00:04:52,316 --> 00:04:54,226 We can copy this from the comments above. 68 00:05:04,372 --> 00:05:12,280 Else, We're going to display a different message based on current grade. 69 00:05:12,280 --> 00:05:14,592 So this is a great place to use a switch statement. 70 00:05:16,137 --> 00:05:19,769 Switch, CurrentGrade. 71 00:05:22,522 --> 00:05:25,492 And then we start with our first case, 9. 72 00:05:30,774 --> 00:05:34,117 Again, we can copy the message from our comments above. 73 00:05:43,552 --> 00:05:48,510 We add our break, and then we're ready for our next case. 74 00:05:48,510 --> 00:05:49,850 We can do the same things for 75 00:05:49,850 --> 00:05:53,180 grades 10 through 12 copying the text from the comments above. 76 00:05:55,913 --> 00:06:00,768 There should be no way to finish this switch statement without the current grade 77 00:06:00,768 --> 00:06:03,242 equal to something between 9 and 12. 78 00:06:03,242 --> 00:06:05,749 But just in case, we can add a default. 79 00:06:16,280 --> 00:06:22,351 Error: Grade Level is not 9-12. 80 00:06:27,116 --> 00:06:28,430 Let's run our script again. 81 00:06:31,940 --> 00:06:37,227 We see this summer school message, because the final average is less than .70. 82 00:06:37,227 --> 00:06:46,480 Let's change that to .88, And run the script again. 83 00:06:48,010 --> 00:06:51,260 This time, we see congratulations on completing your freshman year. 84 00:06:52,750 --> 00:06:56,240 Congratulations on completing this section on conditionals. 85 00:06:56,240 --> 00:06:58,150 To get comfortable with conditionals, 86 00:06:58,150 --> 00:07:01,800 try playing around with any of the code we've written in this section. 87 00:07:01,800 --> 00:07:06,400 Then join me in the next section and explore the compound variable type arrays.