Artificial Intelligence Can Write Programs?!

I wanted to see if ChatGPT could create a simple game in JavaScript.

Open AI’s ChatGPT has been out for a few months now but I’m just getting around to tinkering with it. I was impressed by it’s ability to generate, stories, articles, and reports, but the activity that made me completely lose track of time is generating code.

For example, I told ChatGPT to “Write a really cool game in Javascript” and it responded with an HTML file a JavaScript file to link to it. It explained how the code worked and gave instructions for execution. The resulting web page had buttons labeled Rock, Paper, and Scissors, with the instruction “Choose your weapon:” above them. Clicking the buttons, simply resulted in some text below them, saying whether you won or lost, without telling you what the computer’s selection was.

Next, I wanted to make it more interesting, so I asked “Can you add lizard and spock?”. This is a reference to Sam Kass’s expansion to the classic game of Rock, Paper, Scissors. And it did! It generated new HTML and JavaScript files, with the added buttons, and the more complex JavaScript code! How cool is that? I was just getting started! I then asked it to rename the JavaScript file, which it did, updating the reference in the HTML. Then I said “Can you make it output the computerSelection?” because I wanted to know what the computer’s choice of weapon was. It had no problem generating the code for that. Then I ran it and clicked Spock. The program’s response was “You lose! lizard beats spock.” and I’m like “What? How does a lizard beat a half-Vulcan?” (You probably know if you’re very familiar with Rock-Paper-Scissors-Lizard-Spock.) My next request to ChatGPT wasn’t as smooth.

The story continues in my next post.

Leave a Reply

Your email address will not be published. Required fields are marked *

© Nate the Programmer