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

The Missing Grade چالش 4 از جلسه‌ی 37، متوسط

این برنامه‌ی جاوااسکریپت به هر نمره یک حرف می‌دهد. ولی برای ۵۵ و ۳۰ می‌نویسد undefined.
۱. به ورودی grade نوع number بده.
۲. نوع خروجی را بنویس: : string. حالا خط قرمز می‌گوید مشکل کجاست.
۳. تابع را کامل کن: ۵۰ به بالا C و کمتر از آن D.
خروجی: 95: A، 72: B، 55: C و 30: D.

<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>

<pre id="out"></pre>

<script type="text/typescript">
function grade(score) {
  if (score >= 90) {
    return "A";
  }
  if (score >= 70) {
    return "B";
  }
  if (score >= 50) {
    "C";
  }
}

const scores = [95, 72, 55, 30];
for (const s of scores) {
  show(s + ": " + grade(s));
}
</script>

راهنما و جواب این چالش · برگشت به درس جلسه‌ی 37: اسباب‌کشی، قدم اول · چالش بعدی: Find the Bug

بیشتر بخوان: جاوااسکریپت چیست؟ از دکمه‌ی وب تا Node.js