# Interacting with ChatGPT to Generate NR code

**URL:** <https://discourse.nodered.org/t/interacting-with-chatgpt-to-generate-nr-code/77759>\
**Category:** General\
**Created:** [21 April 2023 00:50 UTC](https://discourse.nodered.org/t/interacting-with-chatgpt-to-generate-nr-code/77759 "2023-04-21T00:50:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [21 April 2023 00:50 UTC](https://discourse.nodered.org/t/interacting-with-chatgpt-to-generate-nr-code/77759/1 "2023-04-21T00:50:36Z")

</div>

Guys, more for the beginners/middle range guys here - but here is a series of interactions i did with ChatGPT that ended up with a great result and what looks like pretty good code to me

This took almost no time - other than cutting and pasting the results and then doing a deploy each time to check

Its quite unbelievable how forgiving it is and also how well it allows you to drill down on a problem through a series of steps rather than having to know it all at the start

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/3/23cde3b3bfe03f7b2cfdcddb7c343c827e20f269.png)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/1/31dc5bdd878054fc2c389b590be276e2e97c3d8d.png)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/b/0ba50a7c7dfe5447a17ba776f1e7bb70f74bd6bd.png)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/5/45a0a55793bfabac9852a38071fc654361ccb445.png)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/5/355d3bbe0a05a513d31ccc37a9c3b129f5247e4b.png)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/3/a3dffd3a4b86d1dcef168ac79f098c34152fac65.png)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/8/3821165609bf609d3b2e7a488a294414ce6ab5e9.png)

Very informative and the description of what each of the code segments does is quite informative - a good tool to send beginners to when they ask some basic question - and something that would give code that is quite similar each time

Craig

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [21 April 2023 07:24 UTC](https://discourse.nodered.org/t/interacting-with-chatgpt-to-generate-nr-code/77759/2 "2023-04-21T07:24:25Z")

</div>

You should prompt it to not use `var`

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [24 April 2023 03:20 UTC](https://discourse.nodered.org/t/interacting-with-chatgpt-to-generate-nr-code/77759/3 "2023-04-24T03:20:34Z")

</div>

I knew there would be a stickler somewhere !

Good Pickup

Craig

---

<div class="post-metadata">

**Author:** ![dougle03](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dougle03/32/32979_2.png) [@dougle03](https://discourse.nodered.org/u/dougle03)\
**Post date:** [24 April 2023 09:21 UTC](https://discourse.nodered.org/t/interacting-with-chatgpt-to-generate-nr-code/77759/4 "2023-04-24T09:21:06Z")

</div>

I use 'var' a lot, is there a reason not to use it?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [24 April 2023 10:06 UTC](https://discourse.nodered.org/t/interacting-with-chatgpt-to-generate-nr-code/77759/5 "2023-04-24T10:06:35Z")

</div>

It is better to use `const` or `let` as appropriate, as it allows the interpreter to generate more efficient code and will trap some bugs that might otherwise get through.

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [24 April 2023 10:10 UTC](https://discourse.nodered.org/t/interacting-with-chatgpt-to-generate-nr-code/77759/6 "2023-04-24T10:10:27Z")

</div>

`var` is not scope aware  
`let` is scope aware

```js
const MyArrayOfArray = [
     [1,2,3],
     [4,5,6],
     [7,8,9]
]

for(var i = 0;i<MyArrayOfArray.length;i++) {

   const Collection = MyArrayOfArray[i]

   /* The below will also increment our first for loop (i is global) - Not good */
   for(var i = 0;i<Collection.length;i++) { 
    ...
   }
}

for(let i = 0;i<MyArrayOfArray.length;i++) {

   const Collection = MyArrayOfArray[i]

   /* This wont */
   for(let i = 0;i<Collection.length;i++) { 
    ...
   }
}

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [23 June 2023 10:10 UTC](https://discourse.nodered.org/t/interacting-with-chatgpt-to-generate-nr-code/77759/7 "2023-06-23T10:10:44Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
