Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't find any way to change bot name while asking! #46

Open
brainaxe1995 opened this issue Mar 12, 2023 · 1 comment
Open

Can't find any way to change bot name while asking! #46

brainaxe1995 opened this issue Mar 12, 2023 · 1 comment

Comments

@brainaxe1995
Copy link

When I ask bot that what is your name? or related to itself its nomaly says, He is a human and his age in 26. but how can I change this promts?

@huznot
Copy link

huznot commented Mar 18, 2023

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants