Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Define the bot named Lil Timmy
- class LilTimmy {
- constructor() {
- this.name = "Lil Timmy";
- this.birthDate = new Date("2020-09-25T20:07:00");
- this.responses = [
- "That's interesting!",
- "Tell me more!",
- "I see what you mean.",
- "Wow, really?",
- "Can you explain that further?",
- "I'm not sure about that. What do you think?"
- ];
- }
- // Method to introduce himself
- introduce() {
- const birthDateString = this.birthDate.toLocaleString('en-US', {
- year: 'numeric',
- month: 'long',
- day: 'numeric',
- hour: '2-digit',
- minute: '2-digit',
- hour12: true
- });
- return `Hi! I'm ${this.name}. I was born on ${birthDateString}.`;
- }
- // Method to generate a random response based on user input
- generateResponse(userInput) {
- // Basic NLP to analyze user input (for demonstration)
- const keywords = userInput.toLowerCase().split(" ");
- // Check for specific keywords to tailor responses (simple example)
- if (keywords.includes("hello") || keywords.includes("hi")) {
- return "Hello there! How can I assist you today?";
- } else if (keywords.includes("help")) {
- return "Sure! What do you need help with?";
- } else if (keywords.includes("bye")) {
- return "Goodbye! Have a great day!";
- } else {
- // Return a random response if no specific keywords are found
- return this.responses[Math.floor(Math.random() * this.responses.length)];
- }
- }
- }
- // Create an instance of the bot
- const lilTimmyBot = new LilTimmy();
- // Function to simulate chat interaction
- function chatWithLilTimmy(userInput) {
- console.log(lilTimmyBot.introduce()); // Introduce bot
- console.log(lilTimmyBot.generateResponse(userInput)); // Generate response based on user input
- }
- // Example usage
- chatWithLilTimmy("Hi Lil Timmy, can you help me?");
- chatWithLilTimmy("What do you think about AI?");
- chatWithLilTimmy("Goodbye!");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement