javascript practice questions answers 1

Here are the answers for this tutorial

https://www.liaoxuefeng.com/wiki/001434446689867b27157e896e74d51a89c25cc8b43bdb3000/001437110841551950380fdc17c4abdaebd38363dbe2348000

var langList = ['Pascal', 'Lua', 'Ruby' ];
for (i = 0; i <langList.length; i ++ )
{
    if($("div ul").html().indexOf(langList[i]) != -1)
    {
        console.log(langList[i]+" exist!");
        continue;
    }
    newnode = document.createElement('li');
    newnode.innerHTML = "<span>"+langList[i]+"<span>"
    $("div ul").append(newnode)
}

var lilist = $("div#test-div>ul>li>span");
s = lilist.map(function(x){return $(this).text();}).sort();
for(let i=0;i<lilist.length;i++)
{
    lilist[i].innerText = (s[i]);
}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324516553&siteId=291194637