Skip to content

Instantly share code, notes, and snippets.

@DestinyLuong
Created November 29, 2017 15:51
Show Gist options
  • Save DestinyLuong/a6bcde91e05803dc5ef40124bfb28d94 to your computer and use it in GitHub Desktop.
Save DestinyLuong/a6bcde91e05803dc5ef40124bfb28d94 to your computer and use it in GitHub Desktop.
Exported from Popcode. Click to import: https://popcode.org/?gist=a6bcde91e05803dc5ef40124bfb28d94
<!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">
<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";
var first = $("#username").val();
var second = $("#password").val();
$("button").click(function(){
if( first === username && second === password){
$("#body").append("Welcome!!!");
} else if(first !== username && second === password){
$("#body").append("Can not find username");
} else if(first === username && second !== password){
$("#body").append("Can not find password");
} else {
$("#body").append("Invalid Entry");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment