| | |
Checking array
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Jan 2008
Posts: 11
Reputation:
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.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
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.
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
> 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.
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
![]() |
Similar Threads
- 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
Views: 1788 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for JavaScript / DHTML / AJAX
acid2 ajax ajaxexample ajaxjspservlets array autoplay blackjack browser captcha captchaformproblem cart child close codes date debugger decimal dependent developer disablefirebug dom element embed engine enter events ext file firefox flash focus form forms frameworks game gears getselection google gxt hiddenvalue highlightedword hint html ie7 ie8 iframe index java javascript javascripthelp2020 javascripts jquery jsp jump libcurl listbox maps marquee masterpage math media menu mp4 onerror onmouseoutdivproblem onmouseover onreadystatechange paypal pdf php player position post programming prototype rated redirect safari scale scriptlets scroll search security size software solutions sources star starrating stretch synchronous toggle tweet unicode variables web webkit webservice window \n






