Week 5 - Problem solving

Problem solving methods

Basic algorithms

Big O notation

Logging

Debugging

Unit testing

AI

Practice

Assignment

Core program

AI, Code Quality & Hallucinations

How to use AI tools responsibly as a developer

AI tools like ChatGPT, Copilot, and others can help you learn faster, solve problems, and write code more efficiently. But they also come with risks—especially when you don’t yet fully understand the concepts behind the code.

This lesson will help you understand:

AI is a tool. You are the developer.


What AI can do well

AI is incredibly helpful for:

Example:

// Ask AI: “Can you explain what this function does?”

AI can explain it in simple terms, provide diagrams, or rewrite it in a more readable form.

💡 Use AI to clarify your thinking, not to replace it.


What AI cannot reliably do

AI does not actually run your code.

It does not know the context of your entire project.

It does not understand your real system unless you describe it perfectly.

AI often struggles with:

And the most important:

⚠️ AI can produce confidently wrong answers.

These are called hallucinations.


What are hallucinations?

A hallucination is when AI gives an answer that sounds correct but is factually incorrect, impossible, or silently wrong.

Examples:

Incorrect APIs

“Use array.remove(3)”

→ JavaScript does not have a remove method.

Incorrect built-in methods

“Use string.reverse()”

→ This method does not exist in JS.

Incorrect logic

Returning the wrong value even though the code looks neat.

Overly complex code

Adding unnecessary loops or conditions.

Misleading explanations

AI explains code incorrectly without realizing it.

💡 AI does not always know that it is wrong—this is why you must verify.


How to avoid AI hallucinations

Always follow these steps:

  1. Verify answers

    Test the code. Read the code. Try small examples.

  2. Ask AI to explain the reasoning

    “Why does this work?”

    If the explanation is vague, something is off.

  3. Cross-check with documentation

    MDN for JavaScript

    Vitest docs

    Node.js docs

  4. Give AI more context

    The more you explain your goal, the better the answer.

  5. Don’t accept long complicated code

    Complexity is a red flag. Ask for a simpler version.

  6. Use debugging tools—not just AI

    Always confirm with the VS Code debugger.

⚠️ The more confident the AI sounds, the more careful you must be.


How to use AI responsibly

Use AI as:

Do not use AI as: