Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![](Vanilla-Login-Form-by-Jobsimulator.svg)
# (Vanilla-Login-Form-by-Jobsimulator.svg)

# JavaScript Login Form by Jobsimulator.Dev
## JavaScript Login Form by Jobsimulator.Dev

![Discord](https://img.shields.io/discord/968893691769000027?color=7289da&label=Discord&logo=discord&logoColor=white&style=for-the-badge)

Expand Down Expand Up @@ -40,4 +40,3 @@ The best way to ask for help is to ask our Discord community.
## Want more challenges?

Browse our [challenges](https://jobsimulator.dev/) and [join our Discord](https://discord.gg/6VsSMZaM7q) to get notified when new challenges are released.

File renamed without changes
11 changes: 7 additions & 4 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,24 @@
<meta charset="utf-8" />
<title>JobSimulator.dev</title>
<link rel="stylesheet" href="styles.css" />
<script src="script.js"></script>
</head>
<body>
<img class="logo" src="images/logo.svg" />
<form>
<!-- TODO: Fix Logo Rendering Issue-->
<img src="/logo.png" />
<img src="images/Vanilla-Login-Form-by-Jobsimulator.svg" />
<span id="success-message" hidden="true">Success!</span>
<span id="error-message" hidden="true">Invalid Credentials</span>
<div class="input-box">
<label for="email">Email</label>
<!-- TODO: Add HTML Email Validation to Email Input -->
<input id="email" type="text" placeholder="Enter your email" />
<input id="email" type="email" placeholder="Enter your email" />
<label for="password">Password</label>
<!-- TODO: Update HTML Password Input to Hide Password Visibility -->
<input id="password" type="text" placeholder="Enter your password" />
<input id="password" type="password" placeholder="Enter your password" />
<button>Submit</button>
<div>
</form>
<script src="script.js"></script>
</body>
</html>
31 changes: 21 additions & 10 deletions src/script.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
const usersTable = [
// Note: This is a fake table for educational purposes. Never store user credentials in plain text.
{ id: 1, username: "[email protected]", password: "badpassword" },
{ id: 2, username: "[email protected]", password: "badpassword" },
{ id: 3, username: "[email protected]", password: "badpassword" },
{ id: 1, username: '[email protected]', password: 'badpassword' },
{ id: 2, username: '[email protected]', password: 'badpassword' },
{ id: 3, username: '[email protected]', password: 'badpassword' },
];
let renderSuccess = () => {
document.getElementById("success-message").hidden = false;
document.getElementById('success-message').hidden = false;
};
let renderError = () => {
document.getElementById("error-message").hidden = false;
document.getElementById('error-message').hidden = false;
};
let resetMessage = () => {
document.getElementById("success-message").hidden = true;
document.getElementById("error-message").hidden = true;
document.getElementById('success-message').hidden = true;
document.getElementById('error-message').hidden = true;
};

addEventListener("submit", (event) => {
addEventListener('submit', (event) => {
event.preventDefault();
resetMessage();

let email = document.getElementById("email").value;
let password = document.getElementById("password").value;
let email = document.getElementById('email').value;
let password = document.getElementById('password').value;

console.log(`email submitted: ${email}`);
console.log(`password submitted: ${password}`);
Expand All @@ -30,4 +30,15 @@ addEventListener("submit", (event) => {
2. If they are, call renderSuccess()
3. If they are not, call renderError()
*/

/*The find method iterates through the usersTable array and checks if there’s an object where both username (email) and password match.*/
const user = usersTable.find(
(user) => user.username === email && user.password === password,
);

if (user) {
renderSuccess();
} else {
renderError();
}
});
37 changes: 34 additions & 3 deletions src/styles.css
Original file line number Diff line number Diff line change
@@ -1,34 +1,65 @@
body {
padding: 0;
margin: 0;
height: 100vh;
display: flex;
flex-direction: column;

/* TODO: Adjust CSS so that form is centered on page */
justify-content: center;
align-items: center;
/*outline: 2px dashed blue;*/
}

form {
display: flex;
justify-content: center;
flex-direction: column;
border: 1px solid black;
padding: 2rem;
border-radius: 2rem;
/*outline: 2px solid red;*/
}

.logo {
margin: 0 auto 10px auto;
max-width: 5%;
}

form > img {
form>img {
margin: auto;
max-width: 100%;
}

.input-box {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}

label {
text-align: left;
text-align: center;
width: 100%;
padding: 1rem 0 0 0;
}

input {
width: 100%;
width: 30%;
padding: 10px 20px;
border-radius: 5px;
outline: none;

}

button {
width: 20%;
margin: 1rem 0 0 0;
padding: 10px 20px;
border: none;
border-radius: 5px;
background-color: darkorange;
color: snow;
}

#success-message {
Expand Down