cf.completefrontend

Predict the outputEasy

What does this chain of method calls log, and where does it break?

What does this log?
const calc = {
  total: 0,
  add(n) {
    this.total += n;
    return this;
  },
  times(n) {
    this.total *= n;
    return this;
  },
  reset() {
    this.total = 0;
  },
};
 
console.log(calc.add(2).times(5).add(1).total);
calc.reset().add(3);
console.log("done");

The answer

Work out every line it logs, in order. Then check.

Checking your sign-in…