ChatGPT writes buggy code, but you can sometimes tell it to write the same code without this specific bug in it and it will fix it. Its like a genie for writing code: you need to specify things very carefully or it will fuck up things that you left up for interpretation.