Giter VIP home page Giter VIP logo

Comments (1)

huznot avatar huznot commented on July 17, 2024 3

Hi.

You can add if and else if statements in script.js.

Type this into script.js:

if (prompt.toLowerCase().trim().replace(/\s+/g, ' ').replace("?", '').replace("'", '') .replace("ur", "your")=== "whats your name") { typeText(messageDiv, "My name is ChatBot"); return; }

What this does is it takes whatever the input the user gives and then it turns it into lowercase, then it removes extra spaces like if they accidently put two spaces. then it removes the question mark, then it removes an apostrophy, then it replaces "ur" with "your", and finally if after doing all of this ; the input is "whats your name", it will say "My name is ChatBot"

its very rare that someone says "whattcha name" or something other than whats your name to a chatbot but if you really want you can put or operators. In javascript, or operators are written like this ||

if (prompt.toLowerCase().trim().replace(/\s+/g, ' ').replace("?", '').replace("'", '') .replace("ur", "your")=== "whats your name" || prompt.toLowerCase().trim().replace(/\s+/g, ' ').replace("?", '').replace("'", '') .replace("ur", "your")=== "whattcha name"

similarily you can add more or operators using || and it will always give back the same output that is inside the if function.

As for the age problem, you can add more else if statements for example

else if (prompt.toLowerCase().trim().replace(/\s+/g, ' ').replace("?", '').replace("'", '').replace("ur", "your") === "whats your age") { typeText(messageDiv, "I have no age, i am an immortal being!"); return; }

Make sure your indentation is correct.

Hope this helps!

from project_openai_codex.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.