User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 391,952 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,837 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 1047 | Replies: 3 | Solved
Reply
Join Date: Jan 2008
Posts: 11
Reputation: n33712 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
n33712 n33712 is offline Offline
Newbie Poster

Checking array

  #1  
Jan 31st, 2008
Hi

Was wondering if anyone can tell me why the code below does not work!
I am presuming it is something to do with the array but can't figure it out.

Thanks


var userpasswords = ['sooty', 'plane', 'sandra', 'football', 'laundry'];
var password;


password = window.prompt('Please enter your password','')

while (password != userpasswords)
{
window.prompt('You have not entered a incorrect password. Please try again','');
};
document.write('You are logged in')
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 6,775
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 23
Solved Threads: 330
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Rebellion Revamped

Re: Checking array

  #2  
Jan 31st, 2008
You need to iterate over the array and compare each array entry against the user input. Currently, you are comparing an array object with a string, hence the error.
for(var i = 0, max = arr.length; i < max; ++i) {
  var found = false;
  if(arr[i] == pwd) {
    found = true;
    break;
  }
}
if(found) {
  alert("Correct password");
} else {
  alert("Incorrect password");
}
"I don't accept change. I don't deserve to live."

"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
Reply With Quote  
Join Date: Jan 2008
Posts: 11
Reputation: n33712 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
n33712 n33712 is offline Offline
Newbie Poster

Re: Checking array

  #3  
Jan 31st, 2008
Hi

Am sorry for this dumb question but am very new to this.
I can follow your code apart from the first line. Could someone possible elaborate on it and explain what everything means?

Thanks for your help so far.

n33712
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 6,775
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 23
Solved Threads: 330
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Rebellion Revamped

Re: Checking array

  #4  
Jan 31st, 2008
> I can follow your code apart from the first line.

I am just stepping through the elements of the array using a loop and comparing each element with the user input. If it matches, then the user has entered a correct password. If all the elements have been tested without a match, then the password is incorrect.

If you still have trouble understanding the basic programming concepts, maybe you should start off with some basic programming / javascript tutorials, practice a lot and attempt your project once you are comfortable with those.
"I don't accept change. I don't deserve to live."

"Working a real job is a win if you're lazy, greedy, or unmotivated. If you're average, you fit right in. And if you're above average, the basic terms of employment and premise of the arrangement is against your interests."
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JavaScript / DHTML / AJAX Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 9:04 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC