...

Exercise: Grade Calculator 2

Building on the previous grade calculator, this exercise teaches a powerful programming pattern: declaring a variable with a default value and conditionally changing it.

Notice how message is set to "passed" by default, since most grades (A, B, C, D) are passing. We only need to change it to "failed" in one place - the else block for F grades!

Your Task

In the else block, set message to "failed". Then run the code and enter a failing score to see how the message variable is updated to the new value.

Expected outputs:

  • Score 95: "You passed with grade: A"
  • Score 45: "You failed with grade: F"
Loading...

Output (Console)