The code should be placed under Remote (Alt+R), preferably a blank, new file (File > New) if you already have scripts loaded there.

And you are right about adding elseif-statements.
For instance, you change "major(5)" to "Captain" and then change "5" to "3".