Here is my script.
<script>
document.querySelector('button').addEventListener('click', (e) => {
e.preventDefault();
const form = document.forms["names"];
console.log('Hello,', form.elements.firstName.value ,form.elements.lastName.value+'!')
form.elements.firstName.value="";
form.elements.lastName.value="";
});
</script>