I find that ChatGPT often spits out code that is either just straight up buggy, or is "correct" but contains extraneous stuff that isn't necessary. As usual, a real programmer (you) still needs to vet the results.