Can you identify the issue with this function and explain why it isn't functioning correctly? The goal was to create a function that performs the following tasks: 1. Define a function named "divide" that accepts one parameter, which is a number. 2. If the number is greater than 20, divide it by 4 and return the result. 3. If the number is greater than 10, divide it by 3 and return the result. 4. Otherwise, divide it by 2 and return the result.
function divide(x) {
if (x > 20) {
document.write(x / 4);
}
else if (x > 10){
document.write(x / 3);
} else {
document.write(x / 2);
}
document.getElementById("demo").innerHTML = divide(23);
}