Changing placement of the code


I was working on this.

In the problem, it asks you to add the following code:

lock.addEventListener(‘click’, function(){
door.removeEventListener(‘click’, openDoor)

but I was wondering would I simply be able to add the

door.removeEventListener(‘click’, openDoor)

to the end of the

lock.onclick = function() {
sign.innerHTML = ‘CLOSED’; = ‘#6400e4’; = ‘lightgray’;

It worked properly, is there an advantage of writing a whole new block of code instead of simply adding something previously written.

1 Like

Yes there is, A big advantage is that you can always be sure that the original is working correctly. So if searching for a bug you only have to look in the code you have written.

Now adding a line on just one place is not a big deal probably, but once you start it never stays with just that one line.

1 Like