🔹 랜덤한 문구를 배열에 객체 형식으로 저장
🔹 난수로 인덱스를 생성
🔹 html에 텍스트 뿌림
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Math
🔸 html
<footer>
<div id="quote">
<span></span>
<span></span>
</div>
</footer>
🔸 js
const quotes = [
{
quote:
'"The name is Sherlock Holmes and the address is 221b Baker street."',
episode: "A Study in Pink",
},
{
quote:
"“I'm not a psychopath, Anderson. I'm a high-functioning sociopath. Do your research.”",
episode: "A Study in Pink",
},
{
quote: '"Bored!"',
episode: "The Great Game",
},
{
quote:
"\"Don't make people into heroes, John. Heroes don't exist. And if they did I wouldn't be one of them.\"",
episode: "The Great Game",
},
{
quote: '"Vatican cameos!"',
episode: "A Scandal in Belgravia",
},
{
quote:
'"Once you\'ve ruled out the impossible, whatever remains, however improbable, must be true."',
episode: "The Hounds of Baskerville",
},
{
quote: '"I don\'t have friends."',
episode: "The Hounds of Baskerville",
},
{
quote: '"Nothing happens to me."',
episode: "A Study in Pink",
},
{
quote: '"It\'s brilliant."',
episode: "A Study in Pink",
},
{
quote: '"Because you\'re an idiot."',
episode: "A Study in Pink",
//나중에는 여기다가 상황에 맞는 이미지를 넣어서 뿌리면 되겠다.
},
];
const quote = document.querySelector("#quote span:first-child");
const episode = document.querySelector("#quote span:last-child");
//const random = Math.round(Math.random() * 10);
//const random = Math.ceil(Math.random() * 10);
const random = Math.floor(Math.random() * quotes.length);
const todaysQuote = quotes[random];
quote.innerText = todaysQuote.quote;
episode.innerText = todaysQuote.episode;