Step 4: The Player's Name چالش 4 از جلسهی 9، سخت
قدم آخر: اسم بازیکن. بالای کد، خط who و کادر name را پیدا کن. داخل جعبهی setName:
- نوشتهی کادر را بخوان.
- در خط who بنویس Player: و بعد اسم با حروف بزرگ (برای Sara: Player: SARA).
- کادر را خالی کن.
امتیاز و پرتابها نباید عوض شوند.
<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 shots = 0;
let board = document.getElementById("board");
let line = document.getElementById("msg");
function press() {
score++;
board.textContent = score;
shots++;
line.textContent = "Shots: " + shots;
}
function three() {
score += 3;
board.textContent = score;
shots++;
line.textContent = "Shots: " + shots;
}
function miss() {
shots++;
line.textContent = "Shots: " + shots;
}
function setName() {
// step 4
}
</script>
راهنما و جواب این چالش · برگشت به درس جلسهی 9: پروژه: تابلوی امتیاز
بیشتر بخوان: جاوااسکریپت چیست؟ از دکمهی وب تا Node.js