I am new at learning JS. I have a problem. I want to print input value by clicking button.
It is my code:
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>Price Tracker</title>
</head>
<body>
<h1>Price Tracker</h1><br>
<form>
<input type="text" id="userInput" placeholder="Enter something">
<button type="button" onclick="click()">Log Input</button>
</form>
<script src="script.js"></script>
</body>
</html>
and js code:
function click() {
const inputValue = document.getElementById('userInput').value;
console.log(inputValue);
}