I just used ChatGPT with gpt4, copied your problem from your post, ran it, and the first result worked just fine.
Might be that you’re using gpt3.5(understandable because not everyone has access), or maybe you asked in a different way than in your post.
Plenty of people have been building simple websites with it, so maybe try to figure out what you’re doing wrong instead of declaring the tool a failure.