From the course: Getting Hands-On with GPT Models: Tips and Tricks

Unlock this course with a free trial

Join today to access over 24,900 courses taught by industry experts.

Generating code with ChatGPT

Generating code with ChatGPT

- [Instructor] You're helping out at a fruit fair and are writing down what everybody wants to eat. You realize you have a big list, but you need a final count to give to the fruit preparation staff. Let's have GPT help us out to write some code for this task. Let's open up our Exercise Files and copy Prompt 1 and go to ChatGPT. So let's take a look at this prompt, "Write some JavaScript that takes in a list of fruits and counts how many there are." So JavaScript is a programming language and it can be run on a web browser. This means that ChatGPT can write this code and also run it at the same time. Let's go ahead and click Enter. Okay, here we go, we have a result. So counts fruit, we go through and we loop through the fruit and we count, and then we have an example here with the results. So example, apple, banana, apple, orange, banana, apple. We have 3, 2, 1. Okay, so this is nice, but how do I validate that this code works? So we can use one of the tools, we can click on Write or…

Contents