Chore Door arrow function randomChoreDoorGenerator()

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

Can someone explain why we don’t write ‘let’ before ‘choreDoor = Math.floor(Math.random() * numClosedDoors);’ in the function?

Also, why is there a condition (choreDoor === 2) written after the else opening bracket in the function? Isn’t it supposed to specify a block of code to be executed, if the same condition is false only?

There are some issues with the video recording and it got me confused how we ended up doing that to have the door randomly assigned.

i would use let, or const, even better, given the value of the variable doesn’t seem to change

can you show me the code (copy paste to the forum) you mention here? Can’t find in the lesson solution.

They didn’t write neither ‘let’ or ‘const’ before choreDoor.

Here’s the code :

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

maybe not, unfortunately that is the reality sometimes. You can have colleagues who have mistakes in there code, part of programming is then figuring out what the right solution is instead

totally redundant. Will report it, thank you :slight_smile:

1 Like