Skip to content

Instantly share code, notes, and snippets.

@dylanerichards
Created January 12, 2017 17:05
Show Gist options
  • Save dylanerichards/24cdb5626205486c270a15fdc3cb8f07 to your computer and use it in GitHub Desktop.
Save dylanerichards/24cdb5626205486c270a15fdc3cb8f07 to your computer and use it in GitHub Desktop.
var header = document.getElementById("header")
var button = document.getElementById("login-button")
button.addEventListener("click", function() {
validateForm()
})
function validateForm() {
if(checkPassword() == true && checkUsername() == true) {
header.innerHTML = "<h1>You're now logged in!</h1>"
} else {
alert("Incorrect!")
}
}
function checkPassword() {
var password = document.getElementById("password").value
if (password == "12345678") {
return true
} else {
return false
}
}
function checkUsername() {
var username = document.getElementById("username").value
var characters = username.split("")
var presence = characters.map(function(element) {
return Number.isInteger(parseInt(element))
})
if (presence.indexOf(true) !== -1) {
return true
} else {
return false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment