In this lesson we'll explore a more complex set of conditions.
Say for example we wanted to create a grading system that converts a student's test score out of 100
marks into a letter grade.
First let's define our grading system let's say that anymore.
Under 50 isn't a fifty to fifty nine is a D sixty to sixty nine is a C seventy to seventy nine is a
B eighty to eighty nine is an A.
And anything over or equal to 90 is an A plus.
Now we can start creating our if statements
we start with if and create our first condition if variable x is less than 15 then output an F next
you'll see a series of else if statements an if statement is used if there are more than two conditions.
In this case there are six conditions.
The second condition states that if x is greater than or equal to 50 and if x is less than 60 output
a D
next.
If x is greater than or equal to 60 and x is less than 70 output a C if x is greater than or equal to
70 and x is less than 80.
Output a B and if x is greater than or equal to eighty and x is less than 90.
Output an A we finish with an else statement which basically instructs our script to put in a plus in
any other scenario since the test was out of 100 and the student couldn't get negative marks.
The only other scenario can be that the mark was equal to or greater than 90.
In which case we've instructed the script to output an A plus
so we've set the value of x to 90.
And you can see in our web browser we get an output of a plus we can test it with other values just
to make sure the script is working.
Let's go ahead and test sixty five
sixty five is greater than or equal to 60 and it's less than 70.
So if our script is working we should get see
Let's go less than 50
less than 50.
Can we output an F so it looks like our script is working.