You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 ||
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; }
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?
The text was updated successfully, but these errors were encountered: