School's Out7:07 with Alena Holligan
In this video we'll recap what you've learned by creating a program for messaging a student based on grade level and final grade average.
//Students class average <70%: //Dear Alena Holligan, //We look forward to seeing you at summer school, beginning July 1st! //Student class average >=70% and current grade 9 //Dear Alena Holligan, //Congratulations on completing your freshman year in High School! We’ll see you on September 1st for the start of your sophomore year! //Student class average >=70% and current grade 10 //Dear Alena Holligan, //Congratulations on completing your sophomore year in High School! We’ll see you on September 1st for the start of your junior year! //Student class average >=70% and current grade 11 //Dear Alena Holligan, //Congratulations on completing your junior year in High School! We’ll see you on September 1st for the start of your senior year! //Student class average >= 70% and current grade 12 //Dear Alena Holligan, //Congratulations! You’ve graduated High School! Don’t forget to come back and visit.
Fabulous work learning all about conditionals. 0:00 In this section, 0:03 we covered the many different operators needed to create descriptive conditionals 0:04 including comparison operators, negation operators, and logical operators. 0:08 We use those conditionals to create nested and combine if statements, and we explored 0:13 the use of a switch statement to compare a single expression to multiple values. 0:18 Let's recap what you've learned by creating a program for 0:23 messaging a student based on the grade level and final grade average. 0:26 Let's create a new file named school.php. 0:32 Again start with our php tags and 0:41 we're ready to map out what we're going to be doing. 0:43 So let's start with comments. 0:47 I'll add these in the teacher's notes so you don't have to type everything. 0:49 If student's class average is less than 70%, 0:52 we're going to send a message that says, dear Alena Holligan, 0:55 we look forward to seeing you at summer school beginning July 1st. 0:59 If the student's class average is greater than or equal to 70, 1:03 and the current grade is 9, the message will read, 1:07 congratulations on completing your freshman year in High School! 1:10 We'll see you on September 1st for the start of your sophomore year! 1:14 If the student's class average is greater than or equal to 70% and 1:18 the current grade is 10, the message will read, 1:22 congratulations on completing your sophomore year. 1:25 And if the current grade is 11, 1:29 congratulations on completing your junior year. 1:31 And finally, if the current grade is 12, 1:35 congratulations you've graduated high school. 1:37 Don't forget to come back and visit. 1:40 The variables we need are first name as a string, 1:42 Last name, Also as a string. 1:49 Current grade, As an integer. 1:55 And our final average. 2:01 Also as an integer. 2:05 Then we'll need a variable for our message body. 2:07 This will be a string as well. 2:13 Let's start with a check to make sure that we have the values for 2:15 the required variables. 2:18 If not firstName or 2:20 not lastName, 2:25 We want to echo, Please enter a student name. 2:32 Let's run our script. 2:39 We see, Please enter a student name, because our firstName and 2:46 lastName variables have an empty string assigned to them. 2:49 Great, let's add Alena Holligan. 2:53 The next thing we want to do is make sure that the current grade is between 9 and 3:01 12 for high school students. 3:06 So we'll add, elseif, 3:09 our current grade is less than 9, 3:12 or our current grade is greater than 12. 3:18 This is only for high school students. 3:28 Please enter a grade between 9 and 12. 3:36 Let's run the script again. 3:43 Now we see that we need a grade between 9 and 12. 3:45 Let's change our current grade 9. 3:48 Next we're ready to show a message for our students based on grade level and 3:52 final grade average. 3:56 So I'm going to put this next section within an else block, 3:57 that displays the message. 4:00 Echo "Dear firstName lastName, 4:06 a newline character" and end the line. 4:11 Then we're also going to echo our messageBody. 4:18 I use double quotes so the variables are expanded. 4:25 Now we're ready to set our message body. 4:29 Within the else block, we add if 4:32 finalAverage is less than .70, 4:37 Our messageBody is going to equal our summer message. 4:47 We can copy this from the comments above. 4:52 Else, We're going to display a different message based on current grade. 5:04 So this is a great place to use a switch statement. 5:12 Switch, CurrentGrade. 5:16 And then we start with our first case, 9. 5:22 Again, we can copy the message from our comments above. 5:30 We add our break, and then we're ready for our next case. 5:43 We can do the same things for 5:48 grades 10 through 12 copying the text from the comments above. 5:49 There should be no way to finish this switch statement without the current grade 5:55 equal to something between 9 and 12. 6:00 But just in case, we can add a default. 6:03 Error: Grade Level is not 9-12. 6:16 Let's run our script again. 6:27 We see this summer school message, because the final average is less than .70. 6:31 Let's change that to .88, And run the script again. 6:37 This time, we see congratulations on completing your freshman year. 6:48 Congratulations on completing this section on conditionals. 6:52 To get comfortable with conditionals, 6:56 try playing around with any of the code we've written in this section. 6:58 Then join me in the next section and explore the compound variable type arrays. 7:01
You need to sign up for Treehouse in order to download course files.Sign up