Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

$(document).ready(function() { var topSites = [ \"Google\", \"Facebook\", \"Twit

ID: 3905140 • Letter: #

Question

$(document).ready(function() {
    var topSites = [
"Google", "Facebook", "Twitter"];
    var links = $("#top_sites").find("a");

    for (var i in topSites) {
        $(links[i]).text = topSites[i];
        $(links[i]).click(
            (function(name) {
                return function() {
                    alert("You clicked on " + name);
                };
            })(topSites[i])
        );
    }
});

(Refer to code example 18-2) When the IIFE is invoked, what happens to the array element (topSites[i]) that’s passed as an argument?

It replaces the links variable.

It becomes the name parameter.

Nothing.

It’s attached as the event handler.

a.

It replaces the links variable.

b.

It becomes the name parameter.

c.

Nothing.

d.

It’s attached as the event handler.

Explanation / Answer

If you have any doubts, please give me comment...

Ans: It's attached as the event handler

When the link is clicked, it will give alert of respective array of value

for 1st link, get alert of "You clicked on Google"

for 2nd link, get alert of "You clicked on Facebook"

for 3rd link, get alert of "You clicked on Twitter"