Thanks heaps for your solution AND the time you have taken to sort out my code in a new fork so that I could see what you meant,
As way of explanation, I got into this mess because I don’t fully understand what
function does and how it works in conjunction with other functions, callbacks, passing argumetns etc. After creating the basic code required to fetch Wikipedia articles I got this idea to grab the associated image too and that’s when things got far more hectic than I thought they would (here was me thinking it would be just another simple ajax call).
I read a bazillion articles on
promise and a zillion solution ideas on StachOverflow, but couldn’t get any of them to work. I literally spent two days on this problem as I didn’t just want to take the easy option and felt I had to get my head around it as much as I could. I learnt a lot - but not that I was after.
However, I did not know about “let” and none of the articles I read mentioned it either. It isn’t been mentioned in FCC tutorials (thinking about the Variable Scope it covers) interestingly and that is the only experience I have in my fledgling code career. Probably a good reason why it isn’t (or I missed it!).
Surprisingly, I actually get what the
let command is doing.
I did take your solution and experiment a little bit - in that I did not declare all the variables with
let - only the ones that are effected by the scope issue. It seems to be working (I didn’t restructure my code either simply because I have got used to looking at it the way it is over the last week - I do appreciate your version though and want to get my code design to that level).
I also found it interesting how you moved the MD5 code to the top, yet it can still be reached by the function that calls it (obviously that code is a cut and paste job - I didn’t even know about MD5 prior to falling down this rabbit hole).
As I said
functions and how they can be called and passed as arguments etc etc - I fell like I am still waiting for the penny to drop.
Thanks again for your help and here is my version of your solution - it’s not as glossy as I would have liked but it’s tweaking and styling I know I can do. This project has chewed up enough time and I want to move one to the next challenge.