title: Javascript: How can I determine if a user has asked the computer the correct series of questions within a specific group (A,B,C) of questions?
body: <p>I'm sorry for the poorly phrased question, hopefully the below explanation of my program can help.</p>
  <p><strong>Summary of program:</strong></p>
  <ol>
  <li>The user will ask the computer a question.</li>
  <li>The question will be matched using regular expressions.</li>
  <li>The computer will respond back to the user depending on if <code>/regular expression/.test</code> is true or not</li>
  </ol>
  <p>I have 3 groups of questions:</p>
  <p><strong>Group A (General Questions):</strong></p>
  <ul>
  <li>What is your name?</li>
  <li>What is your age?</li>
  <li>What is your occupation?</li>
  <li>What is your height?</li>
  </ul>
  <p><strong>Group B (Occupation Questions):</strong></p>
  <ul>
  <li>What is your occupation?</li>
  <li>What is your role in your occupation?</li>
  <li>Do you like your occupation?</li>
  <li>How long have you worked at your occupation?</li>
  <li>Why did you decide to work at your current job?</li>
  </ul>
  <p><strong>Group C (Family Life Questions):</strong></p>
  <ul>
  <li>How many close family members do you have?</li>
  <li>Do you have any sisters or brothers?</li>
  <li>Do you have any kids?</li>
  <li>How is your family going?</li>
  <li>Where would you like to take a holiday with your family?</li>
  </ul>
  <p>Let's consider two scenarios where the user asks questions:</p>
  <p>Scenario 1:</p>
  <ul>
  <li>user asks &quot;What is your name?&quot; (Group A), &quot;What is your age?&quot; (Group A), &quot;What is your occupation?&quot; (Group A), &quot;What is your height?&quot; (Group A)</li>
  </ul>
  <p>Scenario 2:</p>
  <ul>
  <li>user asks &quot;What is your name?&quot; (Group A), &quot;What is your occupation?&quot; (Group B), &quot;Do you like your occupation?&quot; (Group B), &quot;What is your height?&quot; (Group A), &quot;Do you have any kids?&quot; (Group B)</li>
  </ul>
  <p><strong>PROBLEM:</strong>
  I want to be able to determine if a user has asked all/most of the questions in one particular group before moving onto another, and not ask questions scattered across all 3 groups. Any ideas on how I could achieve this? I'm not sure if nested if statements could achieve this?</p>
  <p>Here is a simple sample of my current code:</p>
  <pre><code>    &lt;html&gt;
  
  &lt;form&gt;
  &lt;input id=&quot;userInput&quot; type=&quot;text&quot; placeholder=&quot;Type your question here&quot;&gt;&lt;/input&gt;
  &lt;button type=&quot;submit&quot;&gt;CLICK ME!&lt;/button&gt;
  &lt;/form&gt;
  
  &lt;p id=&quot;computerResponse&quot;&gt;&lt;/p&gt;
      
      &lt;/html&gt;
  </code></pre>
  <p><strong>JAVASCRIPT</strong></p>
  <pre><code>    &lt;script&gt;
      
      var inputValue = document.getElementById(&quot;userInput&quot;).value;
      var computerOutput = document.getElementById(&quot;computerResponse&quot;).innerHTML;
      
  //Some Group A Questions 
  
      if (/what is your name?/ig.test(inputValue)) {
                  computerOutput = &quot;My name is Harry.&quot;;
      };
  
  if (/what is your age?/ig.test(inputValue)) {
                  computerOutput = &quot;I am 20 years old.&quot;;
      };
  
  if (/what is your height?/ig.test(inputValue)) {
                  computerOutput = &quot;I am 20 years old.&quot;;
      };
  
  
  
  //Some Group B Questions
  
  
  if (/do you like your occupation?/ig.test(inputValue)) {
                  computerOutput = &quot;Yes, I do.&quot;;
      };
  
  if (/how long have you worked at your occupation?/ig.test(inputValue)) {
                  computerOutput = &quot;I have worked here for 4 years.&quot;;
      };
  
  if (/why did you decide to work at your current job?/ig.test(inputValue)) {
                  computerOutput = &quot;I am an accountant.&quot;;
      };
  
  
  //Some Group C Questions
  
  if (/do you have any kids?/ig.test(inputValue)) {
                  computerOutput = &quot;Yes, I have a 8 year old daughter.&quot;;
      };
  
  if (/do you have any sisters or brothers?/ig.test(inputValue)) {
                  computerOutput = &quot;Yes, I have one brother.&quot;;
      };
  
  if (/How is your family going?/ig.test(inputValue)) {
                  computerOutput = &quot;They are going great.&quot;;
      };
  
      
      &lt;/script&gt;
  </code></pre>