جواب «Pass or Try Again» چالش 2 از جلسهی 11
سؤال
نمره در score است. با if و else در خط msg بنویس:
- اگر نمره بزرگتر از 49 بود: Pass
- وگرنه: Try again
راهنما
if (score > 49) { line.textContent = "Pass"; } else { line.textContent = "Try again"; }
یک جواب درست
<style>
body { font-family: sans-serif; text-align: center; padding: 16px; }
button, input, select { font-size: 16px; min-height: 40px; margin: 4px; }
</style>
<input id="score" placeholder="0 to 100">
<button id="go" onclick="press()">Go</button>
<p id="msg"></p>
<script>
let line = document.getElementById("msg");
function press() {
let score = Number(document.getElementById("score").value);
if (score > 49) {
line.textContent = "Pass";
} else {
line.textContent = "Try again";
}
}
</script>
اول خودت امتحان کن؛ جوابهای دیگر هم قبول است. برگرد و خودت حلش کن