Collect every failed lookup
A report needs a result for every lookup, including failed ones.
your task
Report every name in its original order. For each name, print its seat count or its lookup error. Finish with “failed: ” followed by the number of failed lookups.
Dover and Elm are both missing. The starter reports only Dover’s error and omits the rooms it found. Each entry in names starts an independent lookup.
Run code runs your code once for each case. It compares what your code prints with the expected output.
Starter code
or press Ctrl EnterNot run yet
cases
Not run yetEvery room exists
Expected output
1
Atlas: 8 seats2
Cedar: 12 seats3
failed: 0See the input and the code for this case
const known = { Atlas: 8, Birch: 4, Cedar: 12 };
function findRoom(name) {
if (name in known) return Promise.resolve({ name, seats: known[name] });
return Promise.reject(new Error("No room named " + name));
}
const names = ["Atlas", "Cedar"];Not run yetTwo rooms are missing
Expected output
1
Atlas: 8 seats2
Dover: No room named Dover3
Birch: 4 seats4
Elm: No room named Elm5
failed: 2See the input and the code for this case
const known = { Atlas: 8, Birch: 4, Cedar: 12 };
function findRoom(name) {
if (name in known) return Promise.resolve({ name, seats: known[name] });
return Promise.reject(new Error("No room named " + name));
}
const names = ["Atlas", "Dover", "Birch", "Elm"];