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

جواب «Find the Red Lines» چالش 5 از جلسه‌ی 36

سؤال

این برنامه‌ی سفارش غذاست: سفارش از waiting به cooking و بعد به ready می‌رود.
سه خط قرمز دارد. هر سه یک دلیل دارند: به‌جای عضو enum، متن یا اسم غلط نوشته شده.
هر سه را درست کن. نوع‌ها و خودِ enum را عوض نکن.
خروجی باید این سه خط باشد:
Please wait: waiting
Please wait: cooking
Come and get it!

راهنما

return "ready"; می‌شود return Status.Ready;، Status.Redy می‌شود Status.Ready، و "waiting" می‌شود Status.Waiting.

یک جواب درست

<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">
enum Status { Waiting = "waiting", Cooking = "cooking", Ready = "ready" }

function next(status: Status): Status {
  if (status === Status.Waiting) {
    return Status.Cooking;
  }
  return Status.Ready;
}

function label(status: Status): string {
  if (status === Status.Ready) {
    return "Come and get it!";
  }
  return "Please wait: " + status;
}

let order: Status = Status.Waiting;
show(label(order));
order = next(order);
show(label(order));
order = next(order);
show(label(order));
</script>

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