js scripts, ifelse and switch