Prompts for Code Documentation Using GPT-4

I’ve found this sequence of prompts helpful. I start by minimizing the code (without mangling!)… then feed that and this series of prompts.Yes, it’s much, much better to document your code from the get-go, but I found this sequence useful if you’ve got undocumented or underdocumented code scraps…


…my minified code block…

Can you help me? I’d like a list of all the functions in this code (in order they appear) with a comment line describing that that function does. Use this format

functionName(); // description here…


  1. checkObjectiveCompletion(objective, conditions); // Checks if an objective is completed based on the conditions provided.



Can you do the same with the variables?


  1. wordswritten; // Stores the number of words written by the player.


Great! Now, can you check and see if there are any duplications or areas where code can be optimized?


Upon examining the code, here are some observations and suggestions for potential optimizations or improvements:

  1. In the updateChapterUI(chapterChanged) function, the following lines seem to be redundant, as they are already present in the displayChapter() function, which is called after it:
currentBook = books.booksToRead.book1;
console.log("Loaded book:", currentBook);
console.log("Current chapter:", getCurrentChapter());

It’s better to remove these lines from updateChapterUI(chapterChanged) to avoid unnecessary duplication.


You can actually ask it for “code review” … it knows what to do :slight_smile:

1 Like

Yup. I like to tinker, though. Thanks for the input!