Skip to content

Instantly share code, notes, and snippets.

@nickheal
Created November 20, 2020 11:27
Show Gist options
  • Save nickheal/7ae8482c9afa52115b83ca84801b852a to your computer and use it in GitHub Desktop.
Save nickheal/7ae8482c9afa52115b83ca84801b852a to your computer and use it in GitHub Desktop.
Complicated concise code
function myFunction(name, telephone, email) {
if (!name || !telephone) {
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,
email
})
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment