I am running some JavaScript and when I click the button the console says the function its calling is not defined. But I did define it above it. I even logged it to the console and it said its a: function () {code}.
Where's the issue?
window.onload = function() {
var userdata = document.getElementById("username").value;
var pwdata = document.getElementById("passwordfield").value;
var check = function() {
alert("hey");
};
console.log(check);
}
<html>
<h1>Login</h1>
<input id="username" type="text" placeholder="Username" name="username">
<input type="password" id="passwordfield" placeholder="Password" name="password">
<button onclick="check()">Log in</button>
</html>
<script src="https://code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>