Thank you all. But it still does not work. The innerHTML does not update to the new text after opening all the doors.
I suspect that the problem is in action 53, but I am not sure…
Now that you’ve written the isClicked()
function, put it to use.
Navigate to the three door element .onclick()
functions and within each function, wrap the current logic within an if
statement to determine if the isClicked()
function has not yet happened for that particular doorImage
.
Adding this logic now protects your game from shortcut victories by making each closed door clickable only once. Open the hint for an example of this functionality.
or action 56 Now that you have the startButton
variable, let’s expand the gameOver()
function.
Add status
as a function parameter and write an if
statement where the condition checks if status
is equivalent to 'win'
. If this condition equates to true, then the innerHTML
of the startButton
should change to You win! Play again?
.
Who can help me???
Thanks:))
//connection doors to html
const doorImage1 = document.getElementById(‘door1’);
const doorImage2 = document.getElementById(‘door2’);
const doorImage3 = document.getElementById(‘door3’);
//images behind doors
const botDoorPath = “https://s3.amazonaws.com/codecademy-content/projects/chore-door/images/robot.svg”;
const beachDoorPath = “https://s3.amazonaws.com/codecademy-content/projects/chore-door/images/beach.svg”;
const spaceDoorPath = “https://s3.amazonaws.com/codecademy-content/projects/chore-door/images/space.svg”;
//number of doors
const numClosedDoors = 3;
//doors open
let openDoor1;
let openDoor2;
let openDoor3;
//door closed
const closedDoorPath = “https://s3.amazonaws.com/codecademy-content/projects/chore-door/images/closed_door.svg”;
//start button
let startButton = document.getElementById(‘start’);
//checking if door opened once
const isClicked = (door) => {
if (door.src === closedDoorPath) {
return false;
} else {
return true;
}
}
//check is game winning condition
const playDoor = () => {
numClosedDoors–;
if (numClosedDoors === 0) {
gameOver(‘win’);
}
}
//randomise the doors
const randomChoreDoorGenerator = () => {
const choreDoor = Math.floor(Math.random() * numClosedDoors);
if(choreDoor === 0) {
openDoor1 = botDoorPath;
openDoor2 = beachDoorPath;
openDoor3 = spaceDoorPath;
} else if(choreDoor === 1) {
openDoor2 = botDoorPath;
openDoor1 = beachDoorPath;
openDoor3 = spaceDoorPath;
} else {
openDoor3 = botDoorPath;
openDoor1 = beachDoorPath;
openDoor2 = spaceDoorPath;
}
}
//when clicked you get new doors
doorImage1.onclick = () => {
if(!isClicked(doorImage1)){
doorImage1.src = openDoor1;
playDoor()
}
}
doorImage2.onclick = () => {
if(!isClicked(doorImage2)) {
doorImage2.src = openDoor2;
playDoor()
}
}
doorImage3.onclick = () => {
if(!isClicked(doorImage3)) {
doorImage3.src = openDoor3;
playDoor()
}
}
//game is over changing the button
function gameOver(status) {
if (status === ‘win’) {
startButton.innerHTML = ‘You win! Play again?’;
}
}
//call of random doors
randomChoreDoorGenerator()