بتل کد Battle Codeدارد باز می‌شود…

جواب «Step 1: Start» چالش 1 از جلسه‌ی 35

سؤال

قدم اول: شمردن. دکمه‌ی Start به تابع start وصل شده، ولی دو تابع خالی‌اند.
- count: یکی به seconds اضافه کند و آن را روی تابلو (board) بنویسد.
- start: تابع count را هر ۱ ثانیه اجرا کند و شماره‌ی setInterval را در timer نگه دارد.

راهنما

در count: seconds++; و board.textContent = seconds; در start: timer = setInterval(count, 1000);

یک جواب درست

<style>
body { font-family: sans-serif; text-align: center; padding: 16px; }
button, input, select { font-size: 16px; min-height: 40px; margin: 4px; }
.lamp { font-size: 80px; width: 130px; margin: 12px auto; border-radius: 24px; background: #334155; filter: grayscale(1); opacity: 0.5; }
.lamp.on { background: #fde047; filter: none; opacity: 1; }
.board { font-size: 40px; width: 200px; margin: 12px auto; padding: 10px; border-radius: 12px; background: #e2e8f0; }
</style>

<div id="board" class="board">0</div>
<div id="lamp" class="lamp">💡</div>
<button id="start">Start</button>
<button id="stop">Stop</button>
<button id="reset">Reset</button>

<script>
let seconds = 0;
let timer;
let board = document.getElementById("board");

function count() {
  seconds++;
  board.textContent = seconds;
}

function start() {
  timer = setInterval(count, 1000);
}

document.getElementById("start").addEventListener("click", start);
</script>

اول خودت امتحان کن؛ جواب‌های دیگر هم قبول است. برگرد و خودت حلش کن