Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8064163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:17:11+00:00 2026-06-05T11:17:11+00:00

I have a javascript chat bot where a person can type into an input

  • 0

I have a javascript chat bot where a person can type into an input box any question they like and hope to get an accurate answer. I can do this but I know I’m going about this all wrong because I don’t know what position the number will appear in the sentence. If a person types in exactly:

what’s the square root of 5 this works fine.

If he types in things like this it doesn’t.

what is the square root of the 5

the square root of 5 is what

do you know what the square root of 5 is

etc

I need to be able to determine where the number appears in the sentence then do the calculation from there. Note the line below is part of a bigger working chatbot. In the line below I’m just trying to be able to answer any square root question regardless of where the number appears in the sentence. I also know there are many pitfalls with an open ended input box where a person can type anything such as spelling errors etc. This is just for entertainment not a serious scientific project. 🙂

if(
    (word[0]=="what's") &&
    (word[1]=="the") &&
    (word[2]=="square") &&
    (word[3]=="root") &&
    (word [4]=="of") &&
    (input.search(/\d{1,10}/)!=-1) &&
    (num_of_words==6)
){        
    var root= word[5];
    if(root<0){ 
        document.result.result.value = "The square root of a negative number is not possible.";
    }else{
         word[5] = Math.sqrt(root);
         word[5] = Math.round(word[5]*100)/100 
         document.result.result.value = "The square root of "+ root +" is "+ word[5] +"."; 
    }
    return true;
}

Just to be clear the bot is written using “If statemments” for a reason. If the input in this case doesn’t include the words “what” and “square root” and “some number” the line doesn’t trigger and is answered further down by the bot with a generic “I don’t know type of response”. So I’m hoping any answer will fit the format I am using. Be kind, I’m new here. I like making bots but I’m not much of a programmer. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T11:17:13+00:00Added an answer on June 5, 2026 at 11:17 am

    You can do this using a regular expression.

    "What is the sqrt of 5?".match(/\d+/g);
    ["5"]
    

    The output is an array containing all of the numbers found in the string. If you have more than one, like “Is the square root of 100 10?” then it will be

    "Is the square root of 100 10?".match(/\d+/g);
    ["100", "10"]
    

    so you can pick what number you want to use in your script.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a 2-person site chat (us and any questioning clients) and I'd like
I basically have a form that you input chat messages into. It looks like
I have JavaScript code which copies the value of input file and paste it
I have javascript string variable with var sttr=We prefer questions that can be answered
I have JavaScript form validation functions like so: function validate_name(field) { if (field ==
I have Javascript as below: <script type="text/javascript" language="javascript"> function redirectToPrevious(abcURL) { window.location.replace(abcURL); } function
I have created some JavaScript files and they run well from my Mac OS
I have a pretty big chat app I'm working on, and had a question
I have the following code, and the javascript console in chrome says Can't read
Is there a way to have a live connection (like for a chat server)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.