Maybe it would also be neater to break this code into two smaller functions (e.g. `showCaption`, `hideCaption`) that you can reuse in the logic here instead of repeat the code.