ChatGPT generated code doesn't work

I forgot to mention, this code doesn't do debounce so is better to use this version.