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 #88

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
63 changes: 52 additions & 11 deletions assets/scripts/login-script.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,66 @@
/*
* Catatan:
* Gunakan fungsi goToHome() untuk menampilkan halaman home
* Gunakan fungsi goToLogin() untuk menampilkan halaman login
* Gunakan fungsi showPopUp() untuk menampilkan pop up error
*/

/** @module Login-Script */
/**
* Membuat variabel loginFormElement untuk tampilan form.
* @constant {HTMLElement}
*/
const loginFormElement = document.querySelector('#loginForm');


/**
* Membuat variabel inputEmailElement untuk tampilan input email.
* @constant {HTMLElement}
*/
const inputEmailElement = document.querySelector('#inputEmail');


/**
* Membuat variabel inputPasswordElement untuk tampilan input password.
* @constant {HTMLElement}
*/
const inputPasswordElement = document.querySelector('#inputPassword');



/**
* Membuat variabel expectedEmail untuk menyimpan informasi email sementara.
* @constant {string}
*/
const expectedEmail = '[email protected]';
const expectedPassword = 'superpassword';



/**
* Membuat variabel expectedPassword untuk menyimpan informasi password sementara.
* @constant {string}
*/
const expectedPassword = 'superpassword'


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


/**
* Membuat variabel email untuk menyimpan nilai email yang didapatkan saat button ditekan.
* @constant {string}
*/
const email = inputEmailElement.value;

/**
* Membuat variabel password untuk menyimpan niali password yang didapatkan saat button ditekan.
* @constant {string}
*/
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();

}
});