Javascript input run a function when specific text is typed in

Two issues:

  1. = is for assignment not equality checking – you want to use ===.
  2. You are storing the value of the input into readInput, so you don’t need to reference value from it:
function readCommand() {
  let readInput = document.querySelector('#commandInput').value
  //           ↓ no .value, it's already here -----------↑
  if (readInput === 'I want an ice cream sandwich') {
  //             ↑ === vs =
  } else {
    alert(`Not a command`);

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top