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

جواب «The Button Box» چالش 3 از جلسه‌ی 7

سؤال

این شمارنده‌ی امتیاز در جاوااسکریپت کار می‌کرد. حالا نوع‌هایش را بنویس:
- جعبه‌ی score نوع number دارد.
- ورودی points نوع number دارد.
- هر دو تابع جوابی برنمی‌گردانند: نوع جوابشان را void بنویس.
با هر بار زدن دکمه، ۵ امتیاز اضافه می‌شود و امتیاز تازه نشان داده می‌شود: اول 5، بعد 10.

راهنما

let score: number = 0; و function addPoints(points: number): void { و function press(): void {

یک جواب درست

<style>
body { font-family: sans-serif; text-align: center; padding: 16px; }
button, input, select { font-size: 16px; min-height: 40px; margin: 4px; }
#out { direction: ltr; text-align: left; font: 16px monospace; margin: 12px 0; padding: 12px; min-height: 28px; border-radius: 12px; background: #0f172a; color: #e2e8f0; white-space: pre-wrap; overflow-wrap: anywhere; }
#out .line { min-height: 22px; }
</style>

<button id="go" onclick="press()">Add 5</button>
<pre id="out"></pre>

<script type="text/typescript">
let score: number = 0;

function addPoints(points: number): void {
  score = score + points;
  show(score);
}

function press(): void {
  addPoints(5);
}
</script>

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