cf.completefrontend

Write the codeEasy

Write an assert(condition, message) helper that throws an AssertionError when the condition is falsy.

AssertionError extends Error and has the name "AssertionError". Without a message, use "Assertion failed". message may also be a function that returns the text, so an expensive message is only built when the assertion fails.

Write this
class AssertionError extends Error {
  // your code
}
 
function assert(condition, message) {
  // your code
}
 
// assert(user.id, "user needs an id");                         // throws if user.id is falsy
// assert(items.length > 0, () => `no items in ${listName}`); // message built only on failure

The answer

Write it yourself first. Then compare it with a reference solution and the checks it passes.

Checking your sign-in…