ChoreDoor - nothing happening

Hi, I’m really stuck on the ChoreDoor project in the Building Interactive JavaScript Websites course and looking for some help. I’ve followed all the steps and followed along with the professional developer video but for some reason when I click ‘save’, nothing happens and the doors remain closed if I click on them.

I suspect it’s something to do with the startRound() function because I’ve tried changing the innerHTML of the Start button to something else, and nothing happens. But I’ve followed the guidance to the letter so I’ve no idea what is wrong!

Here’s the JavaScript:

let doorImage1 = document.getElementById(‘door1’);
let doorImage2 = document.getElementById(‘door2’);
let doorImage3 = document.getElementById(‘door3’);
let startButton = document.getElementById(‘start’);

PLEASE NOTE I don’t know why these show up as ‘Group 14’ etc in the forum post. In the code editor they are proper file paths, and they are set for me before starting the project. I have not changed them.
let botDoorPath = ‘Group 14’;
let beachDoorPath = ‘Group 16’;
let spaceDoorPath = ‘Group 15’;
let closedDoorPath = ‘Group 3’;

let numClosedDoors = 3;
let openDoor1;
let openDoor2;
let openDoor3;
let currentlyPlaying = true;

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

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

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

const playDoor = (door) => {
numClosedDoors–;
if (numClosedDoors === 0) {
gameOver(‘win’);
} else if (isBot(door)) {
gameOver();
}
}

let randomChoreDoorGenerator () => {
let choreDoor = Math.floor(Math.random() * numClosedDoors);
}

if (choreDoor === 0) {
openDoor1 = botDoorPath;
openDoor2 = beachDoorPath;
openDoor3 = spaceDoorPath;
} else if (choreDoor === 1) {
openDoor1 = beachDoorPath;
openDoor2 = botDoorPath;
openDoor3 = spaceDoorPath;
} else if (choreDoor === 2) {
openDoor1 = beachDoorPath;
openDoor2 = spaceDoorPath;
openDoor3 = botDoorPath;
}

doorImage1.onclick = () => {
if (currentlyPlaying && isClicked(doorImage1)) {
doorImage1.src = openDoor1;
playDoor(doorImage1);
}
}

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

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

startButton.onclick = () => {
if (currentlyPlaying === false) {
startRound();
}
}

const startRound = () => {
doorImage1.src = closedDoorPath;
doorImage2.src = closedDoorPath;
doorImage3.src = closedDoorPath;
numClosedDoors = 3;
currentlyPlaying = true;
startButton.innerHTML = ‘Good luck!’;
randomChoreDoorGenerator();
}

startRound();

I haven’t included the HTML or CSS as no changes to these are required for the project, I haven’t touched them but I can include them if it helps.

Thanks in advance!

To preserve code formatting in forum posts, see: [How to] Format code in posts

// You wrote:
let randomChoreDoorGenerator () => {

// Change it to:
let randomChoreDoorGenerator = () => {

Also, move the closing brace of randomChoreGenerator function to the end of the if/else-if blocks.

let randomChoreDoorGenerator = () => {
    let choreDoor = Math.floor(Math.random() * numClosedDoors);
// }  <---- DELETE THIS CLOSING BRACE

    if (choreDoor === 0) {
    ...
    } else if (choreDoor === 2) { 
    ...
    }
}  // <---- CLOSING CURLY BRACE SHOULD BE HERE
2 Likes

Of course! There was nothing actually causing the if { statement to run! The steps in the project don’t say whether it’s inside the randomChoreDoorGenerator() function and I must have missed it in the video.

I’d actually corrected the function declaration syntax on some of my other functions and somehow missed this one too. I’ve made these changes and it now works perfectly, thank you for your help :slight_smile:

1 Like