Incredibly easy: ChatGPT programming for you
About 2 years ago when ChatGPT became accessible to everyone, I immediately created an account out of curiosity about what lay behind the peculiar messages of this new toy. Initially, I amused myself by tormenting the chatbot with questions about the meaning of life, requesting a funny 10-line summary of Goethe's Faust 2, or asking for an age-appropriate bedtime story for my then 6-year-old granddaughter.
Then, I wanted to test the limits of the system and asked questions on topics ChatGPT didn't know the answer to: details about the rear axle of the 1978 Opel Kadett C or where exactly Charlemagne was buried in the Aachen Cathedral in 814. An interesting weakness emerged: when ChatGPT doesn't know, it shamelessly lies to you...
And because programming is my passion (currently for https://cam-ai.de), I also experimented with things like: "Write me a JavaScript program that plays Connect Four." The result was executable...
Nowadays, I regularly use ChatGPT in my programming work, mainly for these purposes:
Me: Here's an excerpt from my JS program:
领英推荐
if (isInViewport(checkelement)) {
trigger_Socket.socket.send(result);
} else {
setTimeout(trigger_Socket.socket.send(result), 5000);
};
The delay of 5 seconds doesn't work like that. Why?
ChatGPT: The issue lies in how setTimeout is being used. setTimeout expects, as its first parameter, a function or a function expression to execute after the delay has elapsed. In your code, trigger_Socket.socket.send(result) is executed immediately and the result of this function is passed to setTimeout. That's not the desired behavior.
To achieve the delay, you need to use setTimeout with a function that calls trigger_Socket.socket.send(result). Here is a corrected version:
if (isInViewport(checkelement)) {
trigger_Socket.socket.send(result);
} else {
setTimeout(function() {
trigger_Socket.socket.send(result);
}, 5000);
};
Done. I find that practical. What do you think?