Chore doors problems


#1

Hi guys

I’m having trouble with the chore door task I think my code has a lot of problems but the main big problem is my doors have stopped opening . If you have time could you look over what I have done more experienced people could probably see my problems. also I’m not totally clear on when its best to use let and when its best to use const. maybe my mistake could be stemming from that, any ways here is my code


#2

let is intended for blocks that until now haven’t had their own scope. Control flow objects fit that bill. for, while and do..while loops, foremost, but switches and if statements have code blocks, too, though one wonders why any scope would be needed in them.

Until we’re told var is deprecated, it makes sense to use it, or const in global scope. var also applies to function scope so doesn’t need replacement in that context.

for (let i = 0; ....

This prevents i from leaking out of the loop body.

Now I don’t know what is being written elsewhere about these keywords. They are all declarative, and all inherent their parent scope (still to be tested and demonstrated). They all have a specific purpose.

const    =>  immutable
var      =>  declares position in scope chain
let      =>  block scope in control flow objects

It makes perfect sense to declare function expressions as constants. That way they cannot be overwritten. But the same applies to objects that we do not want to change. The path URLs make sense, but so too do the cached element nodes.

As for the globals, they can all be var. We would not write,

const currentlyPlaying = true;

since we need to toggle that value, and the above will not allow that. It’s constant. If we look at the startRound function all the globals get defined by it, so all we really need is to declare them all in the initialization phase.

var numClosedDoors, openDoor1, openDoor2, openDoor3, currentlyPlaying;