배열과 반복문 활용하여 네이버 메인의 언론 목록을 구현해보자.
<ul id='news-list'></ul>
let imgArr = [
'https://s.pstatic.net/static/newsstand/2020/logo/light/0604/925.png',
'https://s.pstatic.net/static/newsstand/2020/logo/light/0604/902.png',
'https://s.pstatic.net/static/newsstand/2020/logo/light/0604/422.png',
'https://s.pstatic.net/static/newsstand/up/2020/0708/nsd94830278.png']
appendchild
시킨다.const newsItem = document.createElement('li');
newsItem.className = 'news-item'; // CSS에서 스타일을 적용시키기 위해 class name 부여
const newsImg = document.createElement('img');
newsImg.src = 'url 주소';
newsItem.appendChild(newsImg);
반복문
을 통해 img태그의 src에 이미지 주소를 삽입한다.for (let i = 0; i < imgArr.length; i++) {
const newsItem = document.createElement('li');
newsItem.className = 'news-item';
const newsImg = document.createElement('img');
newsImg.src = imgArr[i];
newsItem.appendChild(newsImg);
}