Skip to content
Aabha AI Academy
Skip to reading

JavaScript · Module 4

Answers and explanations · Turn a rule into a function

Compare these references after your own attempt. You can read them at any time; they do not record a live model or vendor run.

A: a receives the return value Full. b receives undefined, even though the Console displayed Full. Observing output is not the same as returning data.

B: add if (remaining === 1) return "1 place available"; before the general positive return. The resulting function appears in example 08's labels.js.

C:

function canFit(available, requested) {
  return Number.isInteger(requested)
    && requested >= 1
    && requested <= available;
}

The four results are true, false, false, false. The parameter requested is local to a call. A request of 1.5 is deliberately rejected rather than rounded, because rounding would change the request. Under the stated contract, available is already validated; a real boundary should validate that assumption too.

Return to the exercise

Return to this module