🪐 logic
slice(0, index)
해준다🐸 html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" href="index.css" /> <title>New Year Countdown</title> </head> <body> <h1 id="text"> (js로 생성 예정) </h1> <script src="index.js"></script> </body> </html>
🐸 css @import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap'); * { box-sizing: border-box; } body { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100vh; margin: 0; background-color: darksalmon; font-family: 'Roboto', sans-serif; overflow: hidden; } div { position: absolute; bottom: 20px; padding: 10px 20px; background: rgba(0, 0, 0, 0.1); font-size: 18px; } input { width: 50px; padding: 5px; font-size: 18px; background-color: darksalmon; border: none; text-align: center; } input:focus { outline: none; }
🐸 js const textEl = document.getElementById('text') const text = 'I Love Hiking!' let idx = 1; function writeText() { textEl.innerText = text.slice(0, idx) idx++ if (idx > text.length) { idx = 1 } setTimeout(writeText, 2000) } writeText()