The first problem is that you're using a regular string rather than a
Template literal[
^].
The second problem is that
name
is a property on the
window
object. When the event handler function is called, that property hides the
name
variable. Change your variable to something like
fname
instead.
const fname = document.getElementById("fname");
const p = document.getElementById("p");
function full() {
if (fname.value) {
p.innerHTML = `hello, ${fname.value}`;
} else {
p.innerHTML = "hello, who";
}
}
Demo[
^]