•
•
•
•
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
![]() |
•
•
Join Date: Jan 2008
Posts: 11
Reputation:
Rep Power: 1
Solved Threads: 0
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')
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')
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."
"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."
> 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 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."
"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."
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
•
•
•
•
ajax asp cross-browser javascript menu with few lines of code developer development firefox home html internet javascript javascript smooth scrolling scroll smoothly window document position javascript tab menu with rounded corners generator microsoft msdn office prevent javascript menu from getting hidden under flash movies site software sql vista web
- Array help (Java)
- Parallel Array Help (C++)
- how to display one image per day from an array? (JSP)
- C++: compile error "subscripted value is neither array nor pointer" (C++)
- Sorting arrays and then checking for duplicate characters (Java)
- reading from file into array (C++)
- MERGED: Deleting duplicates in an array (plz help me out!!!!!!!) (C)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: pass the value to the text box
- Next Thread: Unlimited DropDown menus



Linear Mode