جواب «Score Board» چالش 6 از جلسهی 2
سؤال
بالای صحنه یک تابلوی امتیاز بساز:
- یک مستطیل سرمهای (navy) از (20, 20)، پهنا ۳۲۰ و بلندی ۶۰.
- دورش یک قاب سفید (white) با کلفتی ۴، درست به همان اندازه.
- یک متغیر let score = 0; و متن "Score: " + score به رنگ سفید، با فونت "bold 28px sans-serif"، وسطِ تابلو: textAlign را "center" کن و متن را در (180, 60) بنویس.
راهنما
تابلو با fillRect(20, 20, 320, 60)، قاب با strokeRect(20, 20, 320, 60) (اول strokeStyle و lineWidth). برای متن: ctx.textAlign = "center"; و بعد ctx.fillText("Score: " + score, 180, 60);.
یک جواب درست
<script>
const ctx = salam.canvas(360, 480);
ctx.fillStyle = "skyblue";
ctx.fillRect(0, 0, 360, 480);
ctx.fillStyle = "navy";
ctx.fillRect(20, 20, 320, 60);
ctx.strokeStyle = "white";
ctx.lineWidth = 4;
ctx.strokeRect(20, 20, 320, 60);
let score = 0;
ctx.fillStyle = "white";
ctx.font = "bold 28px sans-serif";
ctx.textAlign = "center";
ctx.fillText("Score: " + score, 180, 60);
</script>
اول خودت امتحان کن؛ جوابهای دیگر هم قبول است. برگرد و خودت حلش کن