in reply to using if-elsif-else

You are suffering from an excess of curly braces. Lose the curly brace that you have right after each elsif, and also the "matching" curly braces at the end of your else statement. The whole point of elsif is to reduce the clutter of curly braces.

An if ...elsif ... elsif ... else statement looks like this:

if (condition1) { code block } elsif (condition2) { code block } elsif (condition3) { code block } else { code block }
Notice the location of the curly braces. Good luck.