Skip to content

Instantly share code, notes, and snippets.

@LtAstros
Created November 29, 2017 04:18
Show Gist options
  • Save LtAstros/bf24843b8fe3b77e22c0b060cf9e46d1 to your computer and use it in GitHub Desktop.
Save LtAstros/bf24843b8fe3b77e22c0b060cf9e46d1 to your computer and use it in GitHub Desktop.
Exported from Popcode. Click to import: https://popcode.org/?gist=bf24843b8fe3b77e22c0b060cf9e46d1
<!DOCTYPE html>
<html>
<head>
<title>My first If/Else statment</title>
</head>
<body>
<h1></h1>
<input id="username" placeholder="username">
<input id="password" placeholder="password" type="password">
<button> submit</button>
</body>
</html>
{"enabledLibraries":["jquery"],"hiddenUIComponents":["editor.css"]}
//On lines below, complete the missing code. Your goal is to use a conditional statement to check the password.
// If username correct and password correct
// -> "Welcome!!"
// If username correct and password incorrect
// -> "Incorrect Password"
// If username incorrect
// -> "Can not find username"
// Otherwise
// -> "Invalid Entry"
var username = "ScriptEd";
var password = "IL0veC0de";
$("button").click(function(){
var user = $("#username").val();
var pass = $("#password").val();
if (user === username && pass === password) {
$("button").text("Welcome!!");
} else if (user !== username && pass === password) {
$("button").text("Can not find username");
} else if (user === username && pass !== password) {
$("button").text("incorrect password");
} else {
$("button").text("Invalid Entry");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment