<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Momentum App</title>
<link rel="stylesheet" href="CSS/style.css">
</head>
<body>
<form id="login-form" class="hidden">
<input
required
maxlength="10"
type="text"
placeholder="What is your name?" />
<input type="submit" value="Log In" />
</form>
<h2 id="clock">00:00</h2>
<h1 id="greeting" class="hidden"></h1>
<script src="JS/greetings.js"></script>
<script src="JS/clock.js"></script>
</body>
</html>
JS
const clock = document.querySelector("h2#clock");
function sayHello() {
console.log("hello");
// 매 2초마다 이 함수를 실행하고 싶음
}
setInterval(sayHello, 5000);
콘솔:
매 5초마다 hello가 찍힌다.
JS
const clock = document.querySelector("h2#clock");
function sayHello() {
console.log("hello");
}
setTimeout(sayHello, 5000);
결과:
5초 후에 콘솔에 hello가 찍힌다.