Using ChatGPT to Write Code

28 Oct 2023 | ~3 minute read

I wanted to make a small change to the CSS on this site, but wasn't sure how to do it, so I asked ChatGPT to write some code for me.

What I wanted to do was remove the more-links page from this site and replace it with a simple drop-down on the nav menu. I had a fair idea of how to do this, but I wanted an example to build off of.

Usually my first port of call would be DuckDuckGo, but I decided to do it a little differently this time and asked ChatGPT to do it for me instead.

Colour me impressed

The first question I asked was:

Can you make a html navigation menu, with a drop-down that uses no javascript

And immediately it came back with a great example, but the CSS classes in the example were different to the ones I use in my CSS, so I asked ChatGPT to change them:

Can you change nav-menu to main-menu and submenu to sub-menu in the example

I was expecting the bot to have an AI brain fart as it wasn't explicit that I was talking about the class names, but to my surprise it came back with:

Certainly! Here's the updated example with "nav-menu" changed to "main-menu" and "submenu" changed to "sub-menu"...

Bloody hell that's clever!

After this there were a few more hurdles to work around, like stopping the drop-down from going off the right-hand side of the page. Once again ChatGPT was able to help and the result is an okay drop-down menu that I can live with...for now.

Other stuff?

I then tried, just for the lolz, to ask a non-code related question to see how it would react. I asked it to "give me a writing prompt for my blog" and it came back with the following:

Certainly! Here's a writing prompt for your blog:

"Explore the concept of 'Digital Detox' in today's hyper-connected world. Discuss the benefits, challenges, and practical tips for individuals looking to disconnect from screens and technology to find balance and well-being in their lives."

This prompt can lead to a thoughtful and informative blog post on a topic that's relevant to many people in our modern, technology-driven society.

That's spookily similar to some of the stuff I've been writing on this blog recently. 😳

Final thoughts

I'm not thrilled with the sub-menu, but it's better UX than expecting people to go through an entire page load to get to a more-links page. There's still more tweaking to do, I think, but it will do for now.

Next I'd like to improve the menu on mobile - it's currently a details element, which I know isn't great for accessibility, so I really want to fix that.

I think writing code is a great use case for AI models, like ChatGPT, so I might end up using it more code writing in the future. This does beg the question though - is that snippet of code now Copyright to OpenAI, or do I "own" that code because I was the human who asked the question and tweaked the code? Interesting thought...

Have you used ChatGPT to help you with anything like this? I'd love to hear about it - use the reply button below if you have.

Reply by email

← The one before
Some of My Favourite Fonts

Up next →
My First Wet Shave in 15 Years

Want more?

So you've read this post and you're still not satisfied? Ok then, here's some other stuff for you to do: