Error in JavaScript / Robot Name

Hello,

Trying to complete the JS Journey exercises, but forever, this error always appears.

" An error occurred "

We received the following error when we ran your code:

Identifier 'beforeEach' has already been declared

Is anyone facing the same problem?

Are you defining beforeEach in your code somewhere?

If you share your code (using a codeblock and not an image), someone might be better able to help ;)

export class Robot {

  static _namePool = new Map();
  
  constructor() {
    this._name = this._newName();
  }

  _randomName() {
    const letters = [..."ABCDEFGHIJKLMNOPQRSTUVWXYZ"];
    const numbers = [..."0123456789"];
    return letters[~~(Math.random()*26)] +
           letters[~~(Math.random()*26)] +
           numbers[~~(Math.random()*10)] +
           numbers[~~(Math.random()*10)] +
           numbers[~~(Math.random()*10)];
  }

  _newName() {
    let name;
    do {
      name = this._randomName();
    }
    while (Robot._namePool.has(name));
    Robot._namePool.set(name, true);
    return name;
  }
  
  reset() {
    this._name = this._newName();
  }

  get name() {
    return this._name;
  }
}

Robot.releaseNames = () => { Robot._namePool = new Map(); };

This issue was already raised here.

In the meantime, you can download the files and solve the problem locally.

So this error only appears when using the online compiler?

That’s right!

I will try to solve this situation using the local compiler.

Thanks.

1 Like