Reputation: 1
I have read and tried everything I can think of. The other pages that look identical with calling the function onclick work fine. I have tried all I know and read extensively with no avail.
<html>
<head>
<title>Password</title>
</head>
<body>
<div id="output"></div>
<input id="playername" placeholder = "Username" /> <br>
<input id="password" placeholder = "Enter Password"/>
<button onclick="test()">Are you correct?</button>
<script src="pword.js"></script>
</body>
JS:
function test() {
let output = document.querySelector("#output");
let playername = document.querySelector("#playername");
let password = document.querySelector("#password");
if output.value === ("username") && password.value === ("Pa$$w0rd") {
console.log("CORRECT!");
} else {
console.log("Incorrect, try again");
}
}
Upvotes: 0
Views: 45
Reputation: 1
You are checking output.value
instead of playername.value
.
You can have a look at the working code here: https://repl.it/repls/ImaginaryCandidPerformance
Upvotes: 0
Reputation: 17654
You're checking output.value
instead of playername.value
and the parenthesis are misplaced, here's a snippet with fixed code :
function test() {
let output = document.querySelector("#output");
let playername = document.querySelector("#playername");
let password = document.querySelector("#password");
if (playername.value === "username" && password.value === "Pa$$w0rd") {
console.log("CORRECT!");
} else {
console.log("Incorrect, try again");
}
}
<div id="output"></div>
<input id="playername" placeholder="Username" /> <br>
<input id="password" placeholder="Enter Password" />
<button onclick="test()">Are you correct?</button>
Upvotes: 0
Reputation: 2371
You forgot a bracket during your if statement
if HERE => ( output.value === ("username") && password.value === ("Pa$$w0rd") ) <= AND HERE {
console.log("CORRECT!");
} else {
console.log("Incorrect, try again");
}
And it's better to do something like this, remove you'r onclick on HTML and do this :
<button id="MyButton">Are you correct?</button>
var MyBtn = document.getElementById("MyButton");
MyBtn.addEventListener("click", test);
Upvotes: 1
Reputation: 8827
if (playername.value === "username" && password.value === "Pa$$w0rd") {
console.log("CORRECT!");
} else {
console.log("Incorrect, try again");
}
Upvotes: 0