<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Kevin Long</title>
    <description>The latest articles on DEV Community by Kevin Long (@kevinuulong).</description>
    <link>https://dev.to/kevinuulong</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F216785%2F9554781f-c75a-4135-9c01-88dc35e67187.png</url>
      <title>DEV Community: Kevin Long</title>
      <link>https://dev.to/kevinuulong</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kevinuulong"/>
    <language>en</language>
    <item>
      <title>Scanning user input and looking for keywords</title>
      <dc:creator>Kevin Long</dc:creator>
      <pubDate>Sat, 02 Nov 2019 20:02:45 +0000</pubDate>
      <link>https://dev.to/kevinuulong/scanning-user-input-and-looking-for-keywords-431f</link>
      <guid>https://dev.to/kevinuulong/scanning-user-input-and-looking-for-keywords-431f</guid>
      <description>&lt;h1&gt;
  
  
  Original post:
&lt;/h1&gt;

&lt;p&gt;I am trying to load a json file as a javascript object. I then convert the keys into their own array. I am then trying to search through a user input string to find any matches. If a match is found I then want it to then check if the value of that key is "next" and if so do one thing. If the value is not "next" I want it to do a different thing. If none of the keys match any of the words in the user input string I want it to send an error message. This last part seems to be the issue. When a user types a string without a keyword it will sometimes log the error message more than once. I have noticed that this happens especially when a new json file is loaded. &lt;a href="https://github.com/ElderINTERalliance/githubworkshop/blob/master/public/index.html#L54-L104"&gt;Here is a link&lt;/a&gt; to where I think the issue is. I have tried just about everything I can think of but every solution seems to have the same problem so maybe I am just looking in the wrong place. If you have any questions or need more information please let me know.&lt;/p&gt;

&lt;h1&gt;
  
  
  Edit:
&lt;/h1&gt;

&lt;p&gt;I have an object that looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var object = {"keyword": "next", "other word": "wrong", "test": "wrong"}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;it was loaded from a json file accessed from the server using the fetch API. I then have an input box that when a user enters one of the three keys of the object should echo its value on enter. If no keys are found in the string the user has input it should print out an error message. If the value of the key is "next" it should run a function called loadlevel() to load the next level. That next level is then loaded in the same way as the aforementioned one. This appears to be where I am having issues. When it loads the new json file it seems that both the previous object and the new object are still running. This causes it to print out the error message if the new input doesn't match both the new keys. See example below:&lt;/p&gt;

&lt;h2&gt;
  
  
  Setup:
&lt;/h2&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//This is the first object loaded from the json file:
var object = {"keyword": "next", "other word": "wrong", "test": "wrong"}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  What Should happen
&lt;/h2&gt;

&lt;p&gt;When the user inputs the following strings it should have the corresponding outputs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"this is the other word" =&amp;gt; "wrong"
"hello, world" =&amp;gt; "error"
"this is the keyword" =&amp;gt; "next" loadlevel()
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;When the next level is loaded, say this for example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var object = {"smith": "next", "hello": "wrong", "hi there": "wrong"}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;It should then output this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"this is the other word" =&amp;gt; "error"
"hello, world" =&amp;gt; "wrong"
"this is smith" =&amp;gt; "next" loadlevel()
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  What is happening
&lt;/h2&gt;

&lt;p&gt;The first values seem to work fine:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"this is the other word" =&amp;gt; "wrong"
"hello, world" =&amp;gt; "error"
"this is the keyword" =&amp;gt; "next" loadlevel()
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;When the next level is loaded, say this for example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var object = {"smith": "next", "hello": "wrong", "hi there": "wrong"}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;It then outputs this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"this is the other word" =&amp;gt; "error" "error"
"hello, world" =&amp;gt; "wrong" "error"
"this is smith" =&amp;gt; "next" "error" loadlevel()
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



</description>
      <category>help</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
