Refactored js

tenary formatting on if statements to reduce code