Reputation: 25
So this is the code I have and that is called upon when clicking on a page in my nav-bar and the prompt box does come up and ask for input but no matter what I type in nothing happens:
function AlertFunction() {
var person = prompt("Please Enter Password to enter Private Chat");
if (person === Python) {
window.location.pathname = 'index.1.html';
} else {
alert("Sorry you do not have access to this page");
}
}
I'll put website here and try to keep it online that way you can view the page if you would like: https://project-js-imthatguy.c9users.io/index.html
Upvotes: 2
Views: 160
Reputation: 65808
The return value from a prompt()
is always a string. If you want to test the response against the actual value of "Python", it needs to be in quotes. Also, remember that strings are case-sensitive, so "python" doesn't equal "Python".
If Python
is not supposed to be the literal value, then it is a variable and you don't seem to have declared or initialized that anywhere.
function AlertFunction() {
var person = prompt("Please Enter Password to enter Private Chat");
// Strings are case-sensitive
if (person === "Python") {
window.location.pathname = 'index.1.html';
} else {
alert("Sorry you do not have access to this page");
}
}
AlertFunction();
Upvotes: 2
Reputation: 172
Python is not defined, I am assuming you meant to write "Python"
And you shouldn't store passwords inside your HTML/JS or Client side in general. EVER.
Upvotes: 0
Reputation: 943142
Python
is an undeclared variable. When the JS engine tries to read it to compare it to person
, it throws a reference error and aborts the script.
You need to surround it with quotes to make it a string literal.
Upvotes: 1