run displayCode at the right time