For making fields mandatory, visible, or read-only, it is best to use a UI policy. This method uses configuration rather than customization, and is easier to maintain.
Scripting does not need to be done in this case, as you can use UI policy actions to achieve your goal. ServiceNow makes these actions easy to set up with the condition builder.