🎮ArcadeLab

AI Assistant

by PlasmaMeteor43
78 lines2.5 KB
▶ Play
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>AI Assistant</title>
<style>
    body { font-family: Arial, sans-serif; background:#f5f5f5; padding:20px; }
    #chatbox { max-width:650px; margin:auto; background:white; padding:20px; border-radius:8px; }
    .message { margin:10px 0; padding:10px; border-radius:6px; }
    .user { background:#d0e7ff; text-align:right; }
    .assistant { background:#e8e8e8; }
    #inputArea { display:flex; margin-top:20px; }
    #userInput { flex:1; padding:10px; border-radius:6px; border:1px solid #ccc; }
    #sendBtn { padding:10px 20px; margin-left:10px; border:none; border-radius:6px;
               background:#0078ff; color:white; cursor:pointer; }
</style>
</head>
<body>

<div id="chatbox">
    <h2>Offline AI Assistant</h2>
    <div id="messages"></div>

    <div id="inputArea">
        <input id="userInput" type="text" placeholder="Type your message...">
        <button id="sendBtn">Send</button>
    </div>
</div>

<script>
// Simple offline AI logic (no API calls)
function offlineAI(prompt) {
    const text = prompt.toLowerCase();

    // Basic keyword responses
    if (text.includes("hello") || text.includes("hi")) {
        return "Hello! How can I help you today?";
    }
    if (text.includes("name")) {
        return "I'm your offline AI assistant running entirely in your browser!";
    }
    if (text.includes("time")) {
        return "The current time is: " + new Date().toLocaleTimeString();
    }
    if (text.includes("date")) {
        return "Today's date is: " + new Date().toLocaleDateString();
    }
    if (text.includes("help")) {
        return "I can answer simple questions, respond to keywords, and run offline!";
    }

    // Default fallback
    return "I'm not sure how to respond to that, but I'm learning!";
}

// Add message to chat window
function addMessage(text, sender) {
    const msg = document.createElement("div");
    msg.className = "message " + sender;
    msg.textContent = text;
    document.getElementById("messages").appendChild(msg);
}

// Handle Send button
document.getElementById("sendBtn").addEventListener("click", () => {
    const input = document.getElementById("userInput").value.trim();
    if (!input) return;

    addMessage(input, "user");
    document.getElementById("userInput").value = "";

    const reply = offlineAI(input);
    addMessage(reply, "assistant");
});
</script>

</body>
</html>

Game Source: AI Assistant

Creator: PlasmaMeteor43

Libraries: none

Complexity: moderate (78 lines, 2.5 KB)

The full source code is displayed above on this page.

Remix Instructions

To remix this game, copy the source code above and modify it. Add a ARCADELAB header at the top with "remix_of: ai-assistant-plasmameteor43" to link back to the original. Then publish at arcadelab.ai/publish.