Hello!!
I’m not exactly sure how to ask this question and couldn’t find it upon searching.
Here’s the issue:
I’ve completed every task on Chore Door up until number 58. My code isn’t the problem…the task is what has me stumped.
I will quote it:
You’ve written a function to determine if a door’s
src
contains the game-ending ChoreBot image. Now you must apply this logic into currently existing JavaScript functions.The
playOver()
function now needs adoor
argument. After theif
statement in this function, add anelse if
condition that checks if theisBot()
will equate totrue
if you pass thedoor
as theisBot()
argument.
Now here is where I’m confused…there was no previous task relating to writing a playOver() function or what if/else statement to place inside of it.
Am I supposed to figure this out myself? And if so, how? Can someone give me a nudge in the right direction or at least quell my confusion?
As I said before, my code isn’t the issue, I’ve got that part. But if you need the code anyway for reference:
let closedDoorPath = "https://s3.amazonaws.com/codecademy-content/projects/chore-door/images/closed_door.svg"; let startButton = document.getElementById('start');
//Global variables for doors 1-4
let doorImage1 = document.getElementById('door1');
let doorImage2 = document.getElementById('door2');
let doorImage3 = document.getElementById('door3');
let doorImage4 = document.getElementById('door4');
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 loveDoorPath = "https://cq3qna.dm.files.1drv.com/y4mTV0VNAOSTaP28o3ufnSfUj3yzheK_ZO598yGChoqE-bOVWLLe9uO2jFmfJAFsXXOYncta9laeG0xTiP2A-y6ABmVGZncOkaSr1I6ArZFWvSePGjwryHMqHDrfnuSS4Bi8yYqgb1oHfv0UE6SzyKNspmqCLzvSgCuLaVHN8U44wL8kZh_1WHZJPFyebFAQLvRbueLoMhW18ydMm8ND4hzXQ?width=140&height=256&cropmode=none";
//Global Variables for randomDoor
let numClosedDoors = 4;
let openDoor1;
let openDoor2;
let openDoor3;
let openDoor4;
const playOver = (door) => {
if (door === )
}
const isLove = (door) => {
if (door.src === loveDoorPath) {
return true;
} else {
return false;
}
}
//Preventing the "cheaters"
const isClicked = (door) => {
if (door.src === closedDoorPath) {
return false;
} else {
return true;
}
}
//playDoor Functions
const playDoor = () => {
numClosedDoors--;
if (numClosedDoors === 0) {
gameOver('win');
}
}
//Random door generator for game
const randomDoorGen = () => {
let choreDoor = Math.floor(Math.random() * numClosedDoors);
if (choreDoor === 0) {
openDoor1 = loveDoorPath;
openDoor2 = beachDoorPath;
openDoor3 = spaceDoorPath;
openDoor4 = botDoorPath;
} else if (choreDoor === 1) {
openDoor4 = loveDoorPath;
openDoor2 = botDoorPath;
openDoor3 = beachDoorPath;
openDoor1 = spaceDoorPath;
} else if (choreDoor === 2) {
openDoor3 = loveDoorPath;
openDoor1 = spaceDoorPath;
openDoor2 = botDoorPath;
openDoor4 = beachDoorPath
} else {
openDoor2 = loveDoorPath;
openDoor1 = beachDoorPath;
openDoor3 = botDoorPath;
openDoor4 = spaceDoorPath;
}
}
//Functions for opening doors
door1.onclick = () => {
doorImage1.src = openDoor1;
playDoor();
}
door2.onclick = () => {
doorImage2.src = openDoor2;
playDoor();
}
door3.onclick = () => {
doorImage3.src = openDoor3;
playDoor();
}
door4.onclick = () => {
doorImage4.src = openDoor4;
playDoor();
}
const gameOver = (str) => {
if (str === 'win') {
startButton.innerHTML = "You win! Wanna play again?";
}
}
console.log(randomDoorGen());
https://www.codecademy.com/paths/web-development/tracks/building-interactive-javascript-websites/modules/web-dev-interactive-websites/projects/chore-door