Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat's wrong in this JavaScript code?
    text
    copied!<p>I can't figure it out..</p> <p>Markup:</p> <pre><code>&lt;form&gt; &lt;fieldset&gt;&lt;p&gt; &lt;label&gt;Username: &lt;input type="text" name="user" id="user" /&gt;&lt;/label&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt; &lt;label&gt;Password: &lt;input type="password" name="passw" id ="passw" /&gt;&lt;/label&gt;&lt;/p&gt; &lt;label&gt;&lt;input type="submit" value="Log in" name="submitBUT" style="width: 65px; height: 25px; background-color: green; color: white; font-weight: bold;" id="submitBUT" /&gt;&lt;div id="helllo"&gt;&lt;/div&gt;&lt;/label&gt; &lt;/fieldset&gt; &lt;/form&gt; </code></pre> <p>Code:</p> <pre><code>var subBut = document.getElementById('submitBUT'); var users = ['hithere', 'Peter112', 'Geksj', 'lOsja', 'fInduS', '323DssaAA', 'f1fsus']; var passes = ['mllesl', 'Petboy', 'Heneeesh', 'Olga', '234dasdf77/', 'minls', 'ew832ja']; var output = []; function submi(u, p) { for (var i = 0; i &lt; users.length; i++) { if (users[i] == u) { output.push(i); } } for (var o = 0; o &lt; output.length; o++) { if (passes[output[o]] == p) { return p + ' was a correct password.'; } } return 'Error, please try again'; } subBut.onclick = (document.getElementById('helllo').innerHTML=(submi(document.getElementById('user').value, document.getElementById('passw').value))); </code></pre> <p>LIVE CODE; <a href="http://jsfiddle.net/w87MS/" rel="nofollow">http://jsfiddle.net/w87MS/</a></p> <p>and yes, I know you don't store passwords in the source code :D, it's just "fur t3h lulz"</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload