jshreyans / frontend-101

Front-end winter assignment for Department of Visual Media. These include tasks based on Vanilla JS and CSS.
0 stars 1 forks source link

B3 Review #10

Closed jshreyans closed 5 years ago

jshreyans commented 5 years ago

Completed B3 PS: Need Help - I don't know why but the commented out part was not working even though it follows the same logic. So I had to use the inline function definition. Can't find the bug.

LakshSingla commented 5 years ago

You used less than or equal to here for (let i = 0; i <= inputs.length; i++) { therefore it was accessing element out of the array index ( which returns undefined ) causing error to be thrown when you tried to access its addEventListener . Also, the function does not implement the logic for previousCheck previousCheck = this.id;. On correcting these two, it seems to work fine.

PS1: I suggest you ditch accessing elements using an explicit iterative for loop for more cleaner looking array looping techniques. forEach would work here. (I guess since inputs is a DOMTokenList we can't call forEach directly and need to convert it to array using Array.from -> Array.from(intputs).forEach(function(elem, index) { // Do Computation})although I am not completely sure if it is necessary or not.) In any case do have a look at these methods forEach, map, reduce, some, every, find.

jshreyans commented 5 years ago

Thanks a lot for the help and I'll try out the forEach method too.

jshreyans commented 5 years ago

@LakshSingla I went through the various Array methods you mentioned. However, as far as cleaner looking iteration techniques are concerned, I felt the for-of method was the best. It makes the code much more readable.