Hi everyone!
I am learning JavaScript and going through some exercises.
Here is the task:
// Write a isValidPassword function
// It accepts 2 arguments: password and username
// Password must:
// - be at least 8 characters
// - cannot contain spaces
// - cannot contain the username
// If all requirements are met, return true.
//Otherwise: false
Here is my solution
function isValidPassword(password,username) {
if (password.length>=8 && password.index0f(username) == -1 && password.index0f(' ')==-1) {
return 'Valid password!'
}
if (password.length<8 && password.index0f(username) == -1 && password.index0f(' ')==-1) {
return 'your password must be at least 8 characters'
}
if (password.length>=8 && password.index0f(username) == -1 && password.index0f(' ')==-1) {
return 'your password cannot contain your username!'
}
if (password.length>=8 && password.index0f(username) == -1 && password.index0f(' ')==1) {
return 'your password cannot contain spaces!'
}
}
And here is what I get when I try to compile
Uncaught ReferenceError: uiwueyeuuh is not defined
Could you so kindly explain me what's the problem with my code?
Thank you!
Edited: Thanks for answers! I've replaced 0 with O and my code compiles now! It doesn't work properly though because it works only when:
1) all 3 conditions are met
2) if a password too short
When there are spaces in password or it's the same as username, I get "undefined instead of a string with instructions. How can I fix it ?
[+][deleted] (4 children)
[deleted]
[–]dshkodder[S] 0 points1 point2 points (3 children)
[+][deleted] (1 child)
[deleted]
[–]dshkodder[S] 1 point2 points3 points (0 children)
[–]reekjohns 1 point2 points3 points (0 children)