Back to subject
Introduction to PHP/Functions

Build a Grade Calculator

Practical lesson

Write a PHP function called getGrade($marks) that returns "A" for 80+, "B" for 60-79, "C" for 40-59, and "Fail" below 40. Call it with a few different values and echo the results, each on its own line.

Try it yourself
Code

Starter example

Code
<?php
  function getGrade($marks) {
    // your logic here
  }

  echo getGrade(85) . "\n";
  echo getGrade(65) . "\n";
  echo getGrade(30) . "\n";
?>
Live preview
A
B
Fail