Step 2: Three Points چالش 2 از جلسهی 9، متوسط
حالا پرتاب سهامتیازی. داخل جعبهی three:
- سه تا به score اضافه کن.
- score را روی تابلو نشان بده.
هر دو دکمه باید روی همان score کار کنند: +3، بعد +1، بعد +3 باید 7 بدهد.
<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() {
// step 2
}
function miss() {
// step 3
}
function setName() {
// step 4
}
</script>
راهنما و جواب این چالش · برگشت به درس جلسهی 9: پروژه: تابلوی امتیاز · چالش بعدی: Step 3: Count the Shots
بیشتر بخوان: جاوااسکریپت چیست؟ از دکمهی وب تا Node.js