ChoreDoor - why need parameter in playdoor function

Hi All

I have just completed the Chore Door and I was just reviewing the code to makesure I understood it and the only thing I am confused about is why the playdoor function needs the door parameter as the door parameter is not referenced in the function block.

/* EACH TIME DOOR PLAYED DECREASE NUMBER OF AVALIABLE DOORS DOWN. REACH 0 YOU WIN, IF REACH BOT BEFORE ZERO LOSE */
const playDoor = (door) => {
  numClosedDoors--;
  if (numClosedDoors === 0) {
    gameOver("win");
  } else if (isBot(door) === true) {
    return gameOver();
  }
};

Is it because we include a parameter in playdoor function within the onclick functions?

// CHANGE IMAGE OF SOURCE ONCE CLICKED IF NOT ALREADY CLICKED BEFORE AND PLAYING THE GAME
doorImage1.onclick = () => {
  if (!isClicked(doorImage1) && currentPlaying) {
    doorImage1.src = openDoor1;
    playDoor(doorImage1);
  }
};
doorImage2.onclick = () => {
  if (!isClicked(doorImage2) && currentPlaying) {
    doorImage2.src = openDoor2;
    playDoor(doorImage2);
  }
};

doorImage3.onclick = () => {
  if (!isClicked(doorImage3) && currentPlaying) {
    doorImage3.src = openDoor3;
    playDoor(doorImage3);
  }
};

Thanks :grinning:

Oh, but it is… isBot(door).

Oh yes :woman_facepalming: - i have been looking at that for ages! Thank you very much.

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.