Guess the Number چالش 5 از جلسهی 38، سخت
یک بازی حدس عدد بساز.
- با زدن New game یک عدد صحیح تصادفی از 1 تا 10 در متغیر secret بگذار و در msg بنویس Guess!.
- با زدن Try عدد کادر guess را با Number() بخوان:
- اگر با secret برابر بود بنویس Correct!
- اگر از secret کوچکتر بود بنویس Higher
- اگر بزرگتر بود بنویس Lower
<style>
body { font-family: sans-serif; text-align: center; padding: 16px; }
button, input, select { font-size: 16px; min-height: 40px; margin: 4px; }
</style>
<button id="new" onclick="newGame()">New game</button>
<br>
<input id="guess">
<button id="try" onclick="tryIt()">Try</button>
<p id="msg"></p>
<script>
let secret = 0;
let box = document.getElementById("guess");
let line = document.getElementById("msg");
function newGame() {
// your code here
}
function tryIt() {
// your code here
}
</script>
راهنما و جواب این چالش · برگشت به درس جلسهی 38: شانس · چالش بعدی: Find the Bugs
بیشتر بخوان: جاوااسکریپت چیست؟ از دکمهی وب تا Node.js