Sitemap
1 min readNov 12, 2021

--

This challenge was really getting me. I talked to my lead and together we were able to figure out: ‘function superbowlWin(array){const objId = array.find(element => element.result === “W”) return objId.year;’ would work for my test given an array that actually has such an element. However, my test required that if such an element were NOT found, rather than throwing an error, it should return ‘undefined’. That didn’t work until I used the “sources” tab in my dev tools of chrome and in there I was taught about ‘Snippet’. This is like a console but it has a a real cool feature where I can save my code, even after I close and reopen chrome. Then I learned about ‘debugger’ [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/debugger]. With this method, I was able to see that during running, if my function doesn’t find something to match my criteria, my ACTUAL objId will become ‘undefined’ but I was getting an error because undefined can not have a objId.year. So an if , else statement was called for. My working code is: “function superbowlWin(array){
const objId = array.find(element => element.result === “W”)
//debugger — [[this will actually pause my code in running and let me see what it is returning at any given point<removed in final code>]]
if (objId === undefined){
return objId;
}else {
return objId.year;
}

}. Success! Thank you Tomas Tobar :)

--

--