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

جواب «Step 2: Three Points» چالش 2 از جلسه‌ی 9

سؤال

حالا پرتاب سه‌امتیازی. داخل جعبه‌ی three:
- سه تا به score اضافه کن.
- score را روی تابلو نشان بده.
هر دو دکمه باید روی همان score کار کنند: +3، بعد +1، بعد +3 باید 7 بدهد.

راهنما

داخل three بنویس score += 3; و board.textContent = score;. متغیر تازه نساز؛ همان score بالای کد را عوض کن.

یک جواب درست

<style>
body { font-family: sans-serif; text-align: center; padding: 16px; }
button, input, select { font-size: 16px; min-height: 40px; margin: 4px; }
.board { font-size: 40px; width: 200px; margin: 12px auto; padding: 10px; border-radius: 12px; background: #e2e8f0; }
</style>

<p id="who">Player</p>
<div id="board" class="board">0</div>
<button id="one" onclick="press()">+1</button>
<button id="three" onclick="three()">+3</button>
<button id="miss" onclick="miss()">Miss</button>
<p id="msg">Shots: 0</p>
<input id="name" placeholder="Player name">
<button id="set" onclick="setName()">Set name</button>

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

function press() {
  score++;
  board.textContent = score;
}

function three() {
  score += 3;
  board.textContent = score;
}

function miss() {
  // step 3
}

function setName() {
  // step 4
}
</script>

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