"\nHello!\nmy code is the following:\nfor( i=1; i<=5; i++) {\nvar newImage = document.createElement(\u2018img\u2019);\nnewImage.setAttribute(\u2018src\u2019, \u2018images/pic\u2019 + i +\n\u2018.jpg\u2019);\nfunction whatever(e) {\ndisplayedImage.setAttribute(\u2018src\u2019,\ne.target.getAttribute(\u2018src\u2019));\n}\nnewImage.addEventListener(\u2018click\u2019, whatever);\nthumbBar.appendChild(newImage);\n}\nIt seems to be working. My questions are the following:\n\n\nis there a preference for having the function \u2018whatever\u2019\ninside the for loop or outside the for loop? mine is within the\nloop, but the solution code places it outside. Just want to know if\nthere are any cases, and if so, what they are, in which one would\nbe preferable.\n\n\ndoes the placement for the line\n\u2018thumbBar.appendChild(newImage);\u2019 matter, or can it be placed\nanywhere inside the for loop?\n\n\nI see that in the solution code, the function\ndisplayImage(imgSrc) is called before the function is defined, but\nI was under the impression that the code would crash if a function\nis called before it\u2019s defined. can you please clarify the order\nof function calling and definition?\n\n\nAnd finally, just want to say that i found this assessment to be\nchallenging and fun!\n" . . . . . . . . "Embedded HTML5 Microdata Statement 196" . . "\nHi there Patty,\nThanks for sharing your solution. I had a bit of a play, and\nended up with this:\n/* Looping through images */\n\nfunction displayImage(e) {\n displayedImage.setAttribute('src', e.target.getAttribute('src'));\n}\n\nfor(var i = 1; i <= 5; i++) {\n var newImage = document.createElement('img');\n newImage.setAttribute('src', 'images/pic' + i + '.jpg');\n thumbBar.appendChild(newImage);\n newImage.addEventListener('click', displayImage);\n}\n\nI think that if anything this is a better solution than our\nfinal example, although obviously I\u2019ve got the function outside\nthe solution. But you\u2019ve improved on it by adding an event\nlistener, rather than using an onclick handler function. Again,\nremoving a function from the loop.\nIt is generally considered bad practice to include a function\ninside a loop, as it can cause problems in some circumstances. It\nis better to define the function outside the loop and reference it\nfrom inside.\nI am going to update our example when I get the time to use\nsomething more like this. I\u2019ve made a note of it. Thanks again\nfor jogging me on this!\nTo answer your questions:\n\nSee above.\nThere is flexibility here, but it does need to be placed after\nyou have defined newImage, otherwise you\u2019ll get an undefined\nerror.\nthe answer here is \u201Cit depends\u201D \u2014 this stack overflow\npost provides useful reading on bthe matter: \nhttps://stackoverflow.com/questions/9973461/does-a-javascript-function-have-to-be-defined-before-calling-it\n\n" . "Embedded HTML5 Microdata Statement 161" . . <2018-04-30T22:18:34Z> . "Embedded HTML5 Microdata Statement 199" . "Embedded HTML5 Microdata Statement 201" . . <2018-05-01T11:58:12Z> . . . <2018-05-01T11:58:12Z> . . "Embedded HTML5 Microdata Statement 199" . "Embedded HTML5 Microdata Statement 167" . . "2018-05-01T11:58:12Z" . "Embedded HTML5 Microdata Statement 196" . "Embedded HTML5 Microdata Statement 162" . . "Embedded HTML5 Microdata Statement 168" . "Embedded HTML5 Microdata Statement 202" . "\nHi there Patty,\nThanks for sharing your solution. I had a bit of a play, and\nended up with this:\n/* Looping through images */\n\nfunction displayImage(e) {\n displayedImage.setAttribute('src', e.target.getAttribute('src'));\n}\n\nfor(var i = 1; i <= 5; i++) {\n var newImage = document.createElement('img');\n newImage.setAttribute('src', 'images/pic' + i + '.jpg');\n thumbBar.appendChild(newImage);\n newImage.addEventListener('click', displayImage);\n}\n\nI think that if anything this is a better solution than our\nfinal example, although obviously I\u2019ve got the function outside the\nsolution. But you\u2019ve improved on it by adding an event listener,\nrather than using an onclick handler function. Again, removing a\nfunction from the loop.\nIt is generally considered bad practice to include a function\ninside a loop, as it can cause problems in some circumstances. It\nis better to define the function outside the loop and reference it\nfrom inside.\nI am going to update our example when I get the time to use\nsomething more like this. I\u2019ve made a note of it. Thanks again for\njogging me on this!\nTo answer your questions:\n\nSee above.\nThere is flexibility here, but it does need to be placed after\nyou have defined newImage, otherwise you\u2019ll get an undefined\nerror.\nthe answer here is \u201Cit depends\u201D \u2014 this stack overflow post\nprovides useful reading on bthe matter: \nhttps://stackoverflow.com/questions/9973461/does-a-javascript-function-have-to-be-defined-before-calling-it\n\n" . . . "Embedded HTML5 Microdata Statement 197" . . "Embedded HTML5 Microdata Statement 202" . . . . <2018-04-30T22:18:34Z> . . "Embedded HTML5 Microdata Statement 194" . "Embedded HTML5 Microdata Statement 165" . "\"Image gallery\" assessment" . "2018-05-01T11:58:12Z" . . . "\nHi there Patty,\nThanks for sharing your solution. I had a bit of a play, and\nended up with this:\n/* Looping through images */\n\nfunction displayImage(e) {\n displayedImage.setAttribute('src', e.target.getAttribute('src'));\n}\n\nfor(var i = 1; i <= 5; i++) {\n var newImage = document.createElement('img');\n newImage.setAttribute('src', 'images/pic' + i + '.jpg');\n thumbBar.appendChild(newImage);\n newImage.addEventListener('click', displayImage);\n}\n\nI think that if anything this is a better solution than our\nfinal example, although obviously I\u2019ve got the function outside the\nsolution. But you\u2019ve improved on it by adding an event listener,\nrather than using an onclick handler function. Again, removing a\nfunction from the loop.\nIt is generally considered bad practice to include a function\ninside a loop, as it can cause problems in some circumstances. It\nis better to define the function outside the loop and reference it\nfrom inside.\nI am going to update our example when I get the time to use\nsomething more like this. I\u2019ve made a note of it. Thanks again for\njogging me on this!\nTo answer your questions:\n\nSee above.\nThere is flexibility here, but it does need to be placed after\nyou have defined newImage, otherwise you\u2019ll get an undefined\nerror.\nthe answer here is \u201Cit depends\u201D \u2014 this stack overflow post\nprovides useful reading on bthe matter: \nhttps://stackoverflow.com/questions/9973461/does-a-javascript-function-have-to-be-defined-before-calling-it\n\n" . . "Embedded HTML5 Microdata Statement 197" . "Embedded HTML5 Microdata Statement 200" . . . "Embedded HTML5 Microdata Statement 192" . . "Embedded HTML5 Microdata Statement 200" . . . "\nHi there Patty,\nThanks for sharing your solution. I had a bit of a play, and\nended up with this:\n/* Looping through images */\n\nfunction displayImage(e) {\n displayedImage.setAttribute('src', e.target.getAttribute('src'));\n}\n\nfor(var i = 1; i <= 5; i++) {\n var newImage = document.createElement('img');\n newImage.setAttribute('src', 'images/pic' + i + '.jpg');\n thumbBar.appendChild(newImage);\n newImage.addEventListener('click', displayImage);\n}\n\nI think that if anything this is a better solution than our\nfinal example, although obviously I\u2019ve got the function outside\nthe solution. But you\u2019ve improved on it by adding an event\nlistener, rather than using an onclick handler function. Again,\nremoving a function from the loop.\nIt is generally considered bad practice to include a function\ninside a loop, as it can cause problems in some circumstances. It\nis better to define the function outside the loop and reference it\nfrom inside.\nI am going to update our example when I get the time to use\nsomething more like this. I\u2019ve made a note of it. Thanks again\nfor jogging me on this!\nTo answer your questions:\n\nSee above.\nThere is flexibility here, but it does need to be placed after\nyou have defined newImage, otherwise you\u2019ll get an undefined\nerror.\nthe answer here is \u201Cit depends\u201D \u2014 this stack overflow\npost provides useful reading on bthe matter: \nhttps://stackoverflow.com/questions/9973461/does-a-javascript-function-have-to-be-defined-before-calling-it\n\n" . . . "Embedded HTML5 Microdata Statement 194" . . "Embedded HTML5 Microdata Statement 166" . . . . . . . . . . . . . . . . . "\"Image gallery\" assessment" . . . . . . . . "Embedded HTML5 Microdata Statement 195" . . . . . . . . . . . . . . . "Embedded HTML5 Microdata Statement 195" . . . . "Embedded HTML5 Microdata Statement 198" . . . . . . "#10" . . . . . . . "Embedded HTML5 Microdata Statement 201" . . "Embedded HTML5 Microdata Statement 203" . "Embedded HTML5 Microdata Statement 193" . . . "Embedded HTML5 Microdata Statement 198" . . "Embedded HTML5 Microdata Statement 163" . . . . . . "#11" . "#10" . . . "#11" . "Embedded HTML5 Microdata Statement 204" . "\nHello!\nmy code is the following:\nfor( i=1; i<=5; i++) {\nvar newImage = document.createElement(\u2018img\u2019);\nnewImage.setAttribute(\u2018src\u2019, \u2018images/pic\u2019 + i +\n\u2018.jpg\u2019);\nfunction whatever(e) {\ndisplayedImage.setAttribute(\u2018src\u2019,\ne.target.getAttribute(\u2018src\u2019));\n}\nnewImage.addEventListener(\u2018click\u2019, whatever);\nthumbBar.appendChild(newImage);\n}\nIt seems to be working. My questions are the following:\n\n\nis there a preference for having the function \u2018whatever\u2019\ninside the for loop or outside the for loop? mine is within the\nloop, but the solution code places it outside. Just want to know if\nthere are any cases, and if so, what they are, in which one would\nbe preferable.\n\n\ndoes the placement for the line\n\u2018thumbBar.appendChild(newImage);\u2019 matter, or can it be placed\nanywhere inside the for loop?\n\n\nI see that in the solution code, the function\ndisplayImage(imgSrc) is called before the function is defined, but\nI was under the impression that the code would crash if a function\nis called before it\u2019s defined. can you please clarify the order\nof function calling and definition?\n\n\nAnd finally, just want to say that i found this assessment to be\nchallenging and fun!\n" . "Embedded HTML5 Microdata Statement 164" . .