JavaScript_background,quotes

rookieroot·2023년 1월 9일

JavaScript 기초

목록 보기
4/6
post-thumbnail
  1. 명언 랜덤으로 나타내기
const quote = document.querySelector("#quote span:first-child");
const author = document.querySelector("#quote span:last-child");
const todaysQuote = quotes[Math.floor(Math.random()*quotes.length)];
quote.innerText = todaysQuote.quote;
author.innerText =todaysQuote.author;

html

<div id="quote">
        <span></span>
        <span></span>
    </div>
  1. 배경사진 랜덤으로 나타내기
const chosenImage = images[Math.floor(Math.random()*images.length)];
const bgImage = document.createElement("img");
// JS에 html element 생성 
bgImage.src=`img/${chosenImage}`;
//body에 html 추가 prepend는 가장 위에 오게
document.body.appendChild(bgImage);
profile
Develop Process

0개의 댓글