I am struggling to display the output in the console using .value input in javascript
let userName;
document.getElementById('button1').onclick = function() {
userName = document.getElementById('name').value;
console.log(userName);
}
<label>Enter your name: </label><br>
<input type="text" id="name"><br>
<button type="button" id="button1">Submit</button>