DEV Community

Discussion on: I have a problem to use "replaceChild" to active "if" and "else"

Collapse
 
ianowira profile image
Ian Owira

Okay. So your main issues are that you're not using the correct properties for what you're trying to target.

let name = document.getElementById('food').value;

This line is failing because there is no value property for the getElementByID method. It's meant to be innerHTML if you want to retrieve the text value.

document.write(uff);

This here inside your else statement is also incorrect.

  1. 'uff' is a variable that has not been defined.
  2. document.write will clear the entire screen and print out whatever arguments you've placed inside there.

Here you can find a pen of more or less how it should look.