I have used a function which changes the background color according to the user input on mouse click. Also, I want after user inputs a particular color to the input field and presses Enter key, it should change immediately the HTML body background color. Please help me to fix this and write the code in pure javascript.
function changeColor(){
var color = document.getElementById("color").value;
document.body.style.background = color;
}
<p>
Enter your fav colour<input type="text" id="color">
<button onclick="changeColor();" onkeypress="changeColor()";> Click </button>
</p>