Created
November 20, 2020 11:27
-
-
Save nickheal/7ae8482c9afa52115b83ca84801b852a to your computer and use it in GitHub Desktop.
Complicated concise 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) { | |
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, | |
}) | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment