Note that there are some explanatory texts on larger screens.

plurals
  1. POGlobal variables/array question
    primarykey
    data
    text
    <pre><code>Users = new Array; Passwords = new Array; function LogIn() { Users[10] = "username" Passwords[10] = "password" Username = user.value; Password = pass.value; for (i = 0; i &lt;= Users.length; i++) { if (Users[i] == Username) { if (Passwords[i] == Password) { alert("yay!"); } else { alert("nay"); } } } } function Register() { Username = user.value; Password = pass.value; Users.push(Username); Passwords.push(Password); } </code></pre> <p>Alright, so I'm teaching myself Javasctipt in my free time and I decided that the best way would be to just mess around with it for a while. I am trying, currently, to build a primative "log in"/"register" webpage/function and I've obviously run into a few problems. </p> <p>Global variables. I need the arrays "Users" and "Passwords" to be global, but the way I have it set up now, I think they are initialized every single time I call the function-set. So, I guess I'll ask both my questions like this: I realize that arrays probably aren't the best thing for a project like this, however, how do I get the values I store in the arrays to persist from run to run?</p> <pre><code>&lt;script type="text/javascript" src="LogIn.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="Register.js"&gt;&lt;/script&gt; &lt;body&gt; Username: &lt;input type="text" id="user" /&gt; Password: &lt;input type="password" id="pass" /&gt; &lt;input type="button" value="Log In" onClick="LogIn()"/&gt; &lt;input type="button" value="Register" onClick="Register()" /&gt; &lt;hr /&gt; &lt;/body&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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