In this project, you create a document with a simple form that displays the value of a letter grade.

1. Create a new document in your text editor.

2. Type the < !DOCTYPE> declaration, < html> element, document head, and < body> element. Use the strict DTD and "Letter Grades" as the content of the < title> element.

3. Create a script section in the document body that includes the following checkGrade() function and switch statement:

function checkGrade($Grade) {
switch ($Grade) {
case "A":
echo "Your grade is excellent.";
case "B":
echo "Your grade is good.";
case "C":
echo "Your grade is fair.";
case "D":
echo "You are barely passing.";
case "F":
echo "You failed.";
}
}

4. Add code to the switch statement you created in the previous step so that the statements in a case label execute, the switch statement ends.

5. Modify the switch statement so that a default value of "You did not enter a valid grade." Is printed if none of the case labels match the grade variable.

6. Save the document as LetterGrades.php in the Projects directory for Chapter 4.

7. Create a new document in your text editor.

8. Type the < !DOCTYPE> declaration. < html> element, document head, and < body> element. Use the strict DTD and "Letter Grades" as the content of the < title> element.

9. Add the following form to the document body that is submitted to the LetterGrades.php document with a method of "get". The form contains a single text box that you will use to enter a letter grade.

< form action="LetterGrades.php" method="get">
< p>Grade: < input type="text" name="grade" />
< input type="submit" />< /p>
< /form>

10. Save the document as LetterGrades.html in the Projects directory for Chapter 4 and then close it in your text editor.

11. Return to the LetterGrades.php document in your text editor and add a call statement to the end of the script that calls the checkGrade() function and passes to it the value from the grade form variable.

12. Save LetterGrades.php and close it in your text editor.

13. Open the LetterGrades.html file in your Web browser by entering the following URL: http://localhost/PHP_Projects/Chapter.04/Projects/LetterGrades.html. Enter a letter grade and click the Submit button.

14. Close your Web browser window.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.