배열의 랜덤텍스트출력

박범준·2021년 7월 30일
0
var arr = [
{
quote:"인용구1",
author:"작가1"
}
{
quote:"인용구2",
author:"작가2"
}
{
quote:"인용구3",
author:"작가3"
}
quote:"인용구4",
author:"작가4"
}
quote:"인용구5",
author:"작가5"
}
];
var quote = document.getElementByID('quote');
var author = document.getElementByID('author');
var btn = document.getElementByID('btn');
btn.addEventListener('click',function() {
	
    var random = Math.floor(Math.random() *arr.length); //floor 1이하 반올림
    quote.textContent - arr[random].quote;
    author.textContent - arr[random].author;
    

});

profile
HTML/CSS/JAVASCRIPT

0개의 댓글