Created
November 20, 2020 15:12
-
-
Save nickheal/536cab61e8cf0bd05ccc2f1e3d69762d to your computer and use it in GitHub Desktop.
Complicated clear code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function myFunction(name, telephone, email) { | |
const requiredFields = name && telephone; | |
if (!requiredFields) { | |
const modalContainer = document.getElementById('modal-container'); | |
const modal = document.createElement('div'); | |
const basicString = 'Encountered a problem submitting the form. Missing ' | |
if (!name && !telephone) { | |
modal.textContent = basicString + 'name & telephone fields.'; | |
} else if (!name) { | |
modal.textContent = basicString + 'name field.'; | |
} else { | |
modal.textContent = basicString + 'telephone field.'; | |
} | |
modalContainer.appendChild(modal); | |
return; | |
} | |
window.fetch('https://myapi.com', { | |
method: 'POST', | |
body: JSON.stringify({ | |
name, | |
telephone, | |
}) | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment