I'm trying that my script works when I click the button "Say It". But I cant make it work.
I know that I can put an onclick on the html but I need to do it with an addEventListener inside the script.
What am I doing wrong?
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>First Thíngs</title>
<style>
input {
font-size: 2em;
margin: 10px 1px 0;
}
</style>
</head>
<body>
<p>Your city: </p>
<input class="city" type="text">
<p>Your name: </p>
<input class="name" type="text">
<p></p>
<button id="myButton">Say it !</button>
<script>
let city = document.querySelector(".city")
let name = document.querySelector(".name")
function personData(city, name){
alert("I'm from " + city.value + " my name is " + name.value )
}
document.getElementById("myButton").myButton.addEventListener("click", personData);
</script>
</body>
</html>
document.getElementById("myButton").myButton.addEventListenershould bedocument.getElementById("myButton").addEventListenercityandnameareundefinedinsidepersonData; that happens because the function expects to receive some arguments that you never pass to it, rather than reading the values from your input elements