## CodeNewbie Community đ±

Anthony Nanfito

Posted on • Originally published at ananfito.hashnode.dev

# Using ChatGPT as a Coding Buddy

## Intro

Hello, world! Welcome to another blog post for Anthonyâs Techie Thoughts! If youâre new here, my name is Anthony and Iâm studying programming to make a career change from mathematics teacher to a frontend web developer. In my blog posts, I reflect on my journey and share things Iâm learning along the way. You can find me on GitHub, LinkedIn, Hashnode, DEV.to, and CodeNewbie.

In this blog post, Iâll offer a quick reflection on my progress this week and share some thoughts on how I used ChatGPT as a coding buddy.

## Weekly Reflection

This past week has been productive for me. This is mostly because Iâm currently on a mid-term break from work and I have extra time I can dedicate to my studies. Which I am thoroughly enjoying. Hereâs a quick list of my accomplishments this week:

## Using ChatGPT as a âcoding buddyâ

On a whim, I decided to make use of ChatGPT as a âcoding buddyâ by asking it questions when I got stuck or needed a sounding board. As a self-taught dev, this is one of the things Iâve struggled with the most. Sometimes I wish I could just tap someone on the shoulder and say, âHey, what do I need to make this work?â Or âThis is what Iâm thinking for this problem. Is that the right approach?â However, this isnât always an easy option so this week I tried something different: I asked ChatGPT.

For example, I was working on a function earlier this week for my Learning Journal project where I needed it to return the first three elements of an array, but I couldnât figure out what method I needed to use. Initially, I thought I could use the `.filter()` method, but further down youâll see how ChatGPT corrected me on that idea. First I asked it, âHow do I write a function in JavaScript to return the first 3 items in an array?â Here is the response I received:

When I asked my âcoding buddyâ this question the first thing it mentions is the `.slice()` method and I was like, âOh! duh! Of course, why didnât I think of that?â As requested, it did write an entire function for returning the first 3 elements of an array, but I didnât need the entire function. I just needed that little hint to use `.slice()` instead of `.filter()`. When I asked it if I could use the `.filter()` method it explained why it wasnât possible and why I should use the `.slice()` method instead:

(NOTE: While writing this blog post, I noticed that my initial question here has a typo in the first part of the question. Iâm not sure why my brain decided to write âIs it possible to write return âŠâ but ChatGPT seems to have correctly interpreted this to mean âIs it possible to write a function that returns the first âŠâ This is interesting, but could also just be a random occurrence. In the big picture, Iâm not sure if ChatGPT is always good at interpreting human miscommunication.)

This second explanation helped me realize the error in my initial approach and redirect toward a solution that worked. Of course, this is information could have obtained from someone in a Discord community, a forum, or even through reading through webpages and documentation, but those come with a longer time commitment. Here, in a few minutes, I got some advice on the direction I needed to go as well as some examples to reference. In fact, in this case, I just needed a nudge in the right direction. As a self-taught dev, this is particularly useful because I canât just lean over to the next cubicle and ask a coworker quick questions like these. But, for now, I can ask ChatGPT and it (might) give me an answer to ânudgeâ me in the right direction.

### Closing thoughts on ChatGPT

As impressive as it ChatGPT is (and other AI software like it), weâve already seen examples of where it will hallucinate and present incorrect information. With that in mind, I do not think it is a good idea to ask it to do a specific task for you.

For example, Iâm sure I could have given it more information and context about how and why I needed a function to return the first three elements of an array, but that would have defeated the purpose of studying. To me, that is the equivalent of having someone else do your work for you. Which doesnât help you become a better developer.

I tell my students, âthe person who holds the pencil learns the math.â Meaning, the person who is sitting there going through the steps (and perhaps struggling a bit) to solve the problem is the one who will learn and remember it. In this case, the person who types on the keyboard learns to code.

All that said, I do think this could become another tool within our developer toolbox. We have a plethora of resources already at our deposal: freeCodeCamp, Stackoverflow, W3 Schools, YouTube, Discord Communities, and more! This is an addition to that and perhaps it might fill in some gaps that the others donât provide or donât meet the needs of the learner. I think this is how Iâll use it moving forward (and continue to use it as long as it proves useful). Itâs one tool in a vast toolbox of tools to help me learn how to code and get better at achieving my goal of making a career switch.

## Thanks for reading

Thanks so much for reading this post. Have you used ChatGPT in your studies? If so, how have you been using it? Has it been helpful? Leave your thoughts in the comments below. Hearing your thoughts makes this more of a conversation and helps everyone learn.