You can put this if in the duration === "" a if with an ||

This way, you don't need to cache the previousDurationTimeCode, as you'll only be using it once.