JavaScript

#6.1 Background

김예나 2023. 2. 13. 16:05
const images = ["0.jpg","1.jpg","2.jpg"]; //폴더 안에 있는 이미지 이름이랑 똑같게

const chosenImage = images[Math.floor(Math.random()*images.length)];

const bgImage = document.createElement("img"); //img요소 생성

bgImage.src = `img/${chosenImage}`;

document.body.appendChild(bgImage) //body에 html추가(가장 뒤에)