Chore Door Step 70

https://www.codecademy.com/paths/web-development/tracks/build-interactive-websites/modules/web-dev-interactive-websites/projects/chore-door

Start Button won’t Reset Game - Problem occurred on the final step when adding if statement (lines 89-91)
Please help!

// Store the img element via it 'Id'
let doorImage1 = document.getElementById('door1');
let doorImage2 = document.getElementById('door2');
let doorImage3 = document.getElementById('door3');

// Store Alternative Image path
let botDoorPath = 'https://s3.amazonaws.com/codecademy-content/projects/chore-door/images/robot.svg';
let beachDoorPath = 'https://s3.amazonaws.com/codecademy-content/projects/chore-door/images/beach.svg';
let spaceDoorPath = 'https://s3.amazonaws.com/codecademy-content/projects/chore-door/images/space.svg'
let closedDoorPath = 'https://s3.amazonaws.com/codecademy-content/projects/chore-door/images/closed_door.svg';
let currentlyPlaying = true;

// Store for Random Generator
let numClosedDoors = 3;
let openDoor1;
let openDoor2;
let openDoor3;

const isBot = door => {
  if(door.src === botDoorPath) {
    gameOver(); 
    return true;
  } else {
    return false;
  }
};

let isClicked = door => {
  if(door.src === closedDoorPath) {
     return false;
  } else {
    return true;
  }
};

let playDoor = (door) => {
  numClosedDoors--;
  if(numClosedDoors === 0) {
     gameOver('win');
  } else if(isBot(door)) {
    gameOver();
	}
  
};

let randomChoreDoorGenerator = () => {
  let choreDoor = Math.floor(Math.random() * numClosedDoors);
  if(choreDoor === 2) {
    openDoor1 = botDoorPath;
    openDoor2 = beachDoorPath;
		openDoor3 = spaceDoorPath;
  } else if (choreDoor === 1) {
    openDoor2 = botDoorPath;
    openDoor3 = beachDoorPath;
		openDoor1 = spaceDoorPath;
	} else {
    openDoor3 = botDoorPath;
    openDoor1 = beachDoorPath;
		openDoor2 = spaceDoorPath;
  }
};


// Change "src" to Alternative Image path
doorImage1.onclick = () => {
  if(!isClicked(doorImage1) && currentlyPlaying) {
  	doorImage1.src = openDoor1;
  	playDoor(doorImage1);
	}
};

doorImage2.onclick = () => {
  if(!isClicked(doorImage2) && currentlyPlaying) {
  	doorImage2.src = openDoor2;
  	playDoor(doorImage2);
  }
};

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

// START BUTTON
let startButton = document.getElementById('start');
startButton.onclick = () => {
  if(!currentPlaying) {
  	startRound();
	}
};

// RESET all variables for New Game
const startRound = () => {
  door1.src = closedDoorPath;
	door2.src = closedDoorPath;
	door3.src = closedDoorPath;
  
	startButton.innerHTML = 'Good luck!';
	numClosedDoors = 3;
	currentlyPlaying = true;
	randomChoreDoorGenerator();
};

 // GAME OVER
const gameOver = (status) => {
  if(status === 'win') {
     startButton.innerHTML = 'You win! Play again?';
  } else {
    startButton.innerHTML = 'Game over! Play again?';
  }
  currentlyPlaying = false;
};

startRound();

Your issue is that you can’t reset a lesson ?

Chore Door - is a game with “Game Over” and “ReStart Game button” which “Resets the game”!
The issue is with my code on line 89-91.
When following the final step (Step 70) it causes the functionality of the Start Button to become non-functional! And I am not sure why this is happening.
I’ve followed the walk-through video and as far as i can see it’s the same.

if(!currentPlaying) {
  	startRound();
	}

Error is in here, and as stupid as it sounds, you slap yourself on the head…
You missed ly in !currentlyPlaying :stuck_out_tongue:

1 Like

Brilliant. Thanks for your help.

1 Like

Sorry I didn’t check the lesson and misunderstood you.

Thanks @janneslohmeijer

3 Likes

This topic was automatically closed after 47 hours. New replies are no longer allowed.