Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update login-script.js #91

Open
wants to merge 1 commit into
base: 02-solution-study-case
Choose a base branch
from
Open
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
25 changes: 15 additions & 10 deletions assets/scripts/login-script.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
/*
* Catatan:
* Gunakan fungsi goToHome() untuk menampilkan halaman home
* Gunakan fungsi goToLogin() untuk menampilkan halaman login
* Gunakan fungsi showPopUp() untuk menampilkan pop up error
*/

/* Comment : Membuat variabel untuk setiap elemen view. */
const loginFormElement = document.querySelector('#loginForm');
const inputEmailElement = document.querySelector('#inputEmail');
const inputPasswordElement = document.querySelector('#inputPassword');


/* Comment : Membuat variabel untuk menyimpan informasi email dan password. */
const expectedEmail = '[email protected]';
const expectedPassword = 'superpassword';


/* Comment : Menambahkan aksi klik pada button. */
loginFormElement.addEventListener('submit', function(event) {
event.preventDefault();


/* Comment : Mendapatkan nilai dari masing-masing input (email dan password) ketika tombol ditekan. */
const email = inputEmailElement.value;
const password = inputPasswordElement.value;

/* Comment : Memastikan bahwa nilai email dan password sesuai dengan nilai yang tersimpan. */
if (email == expectedEmail && password == expectedPassword) {

/* Comment : Jika sesuai maka program akan berpindah ke halaman home. */
goToHome();

} else {

/* Comment : Namun jika tidak sesuai maka akan menampilkan informasi bahwa input salah. */
showPopUp();

}
});