IT/개발

#6 [2021 UPDATE] QUOTES AND BACKGROUND

공장장J 2022. 3. 30. 09:48
반응형

#6.0 Quotes
명언과 작가 랜덤하게 표출시키기

Math.random()과 Math.floor()
배열A[Math.floor(Math.random() * 배열A.length)];


<index.html>


Math.random()
0~1 사이의 랜덤 숫자를 제공하는 자바스크립트 함수

Math.round()
반올림 함수


Math.ceil()
올림 함수


Math.floor()
내림 함수


배열 길이 알려줌 .lenth


<quotes.js>

const quotes = [
{
quote: "abcdefg",
author: "a"
},
{
quote: "hahahahahahahahaha",
author: "banana"
},
{
quote: "hi!!!!!!!!",
author: "apple"
},
{
quote: "good morning",
author: "cccc"
},
{
quote: "nice to meet you",
author: "hoho"
},
];

const quote = document.querySelector("#quote span:first-child");
const author = document.querySelector("quote span:last-child");

const todaysQoute = quotes[Math.floor(Math.random()*quotes.length)];

quote.innerText = todaysQoute.quote;
author.innerText = todaysQoute.author;

==========================
#6.1


반응형