tolong kak 2 hari nggak bisa nih "// Tambahkan kode JavaScript kalian di file ini
// Function to handle form submission
function handleGetFormData() {
return {
name: document.getElementById(‘name’).value,
city: document.getElementById(‘city’).value,
email: document.getElementById(‘email’).value,
zipCode: document.getElementById(‘zip-code’).value,
status: document.getElementById(‘status’).checked
};
}
// Function to check if a string consists only of numbers
function isNumber(str) {
return /^\d+$/.test(str);
}
// Function to check if checkbox is checked
function checkboxIsChecked() {
return document.getElementById(‘status’).checked;
}
// Function to validate form data
function validateFormData(formData) {
// Check if formData object is not null or undefined
if (!formData) {
return false;
}
// Check if all required fields are filled
if (
formData.name &&
formData.city &&
formData.email &&
formData.zipCode &&
isNumber(formData.zipCode) &&
formData.status
) {
return true;
} else {
return false;
}
}
form.addEventListener(‘click’, (event) => {
event.preventDefault();
submit()
})
function submit() {
const data = handleGetFormData();
// Mendapatkan elemen dengan id ‘warning’
const warningDiv = document.getElementById(‘warning’);
// Jika isValid adalah false, tampilkan pesan peringatan
if (validateFormData(data) == false) {
return (warningDiv.textContent = ‘Periksa form anda sekali lagi.’);
} else {
return warningDiv.remove();
}
}
// Event listener to call submit function on form submit
document.getElementById(‘form’).addEventListener(‘submit’, submit);
"