앞에서 했던게 바로 이거죠
const messages = [
{title: "book1 title", author:"sungpah"},
{title: "book2 title", author:"david"},
{title: "book3 title", author:"paul"}
];
const generateRandomIndex = () => {
return Math.floor(Math.random() * messages.length);
}
const showTitle = () => {
randomIndex = generateRandomIndex()
alert(`book: ${messages[randomIndex].title} author: ${messages[randomIndex].author}) //이렇게 바꾸는 거죠!
}
setInterval(() => {
showTitle()
}, 1000)
오늘 우리의 과제는
그래서 우리가 알아야 할 것은 브라우저에 띄운 다는게 뭔지 이해 하면 됩니다.
이제까지 작성한 저 코드들은 일단 그대로 두고, 이제 부턴 새로운 파일을 만들어 봅시다!
여러분이 설정한 경로에서 파일을 하나 만들어 봅시다.
index.html
이라는 이름으로 지어보세요! 파일을 연 후
<body>
</body>
<script>
</script>
요렇게 한 번 만들어 보세요. 자 우리의 눈에 보이는 body tag안에 집어 넣을 거고, 우리가 작성한 javascript를 <script>에 짚어 넣는거죠. 요렇게요