An unexpected error in JavaScript / Translation Service

I get this error and I can’t continue with the exercise, can someone help me?

  1. Please share your code and the error using codeblocks, not screenshots!
  2. The error says exactly what is wrong. Your code is missing a semicolon and isn’t valid syntax without it.

Good morning.

But it asks me for a semicolon in the statement of the function, no matter what code I write inside, and if I put the semicolon it asks me for another semicolon below.

I can’t test what I write or anything because I always get that error.

 request(text) {
 
 }

This code gives me the same error.

That is a function call, not a function definition. A function definition starts with function. A function call needs a semicolon after the ).

Can you share your complete code, please? Using text and a codeblock? Images are hard to copy paste and hard to read.

Of course, I’m sorry, I’m a total novice and I don’t know the terminology or the functioning of these sites.

I will try to explain well, I started completing the first two tasks of the exercise, which by the way gave me a lot to do jejejej. And when I reached the third task began to jump me that error.

Here I paste all the code that there is, I work in the online editor, if you need to know.

// @ts-check
//
// The lines above enable type checking for this file. Various IDEs interpret
// the @ts-check and reference directives. Together, they give you helpful
// autocompletion when implementing this exercise. You don't need to understand
// them in order to use it.
//
// In your own projects, files, and code, you can play with @ts-check as well.

export class TranslationService {
  /**
   * Creates a new service
   * @param {ExternalApi} api the original api
   */
  constructor(api) {
    this.api = api;
  }

  /**
   * Attempts to retrieve the translation for the given text.
   *
   * - Returns whichever translation can be retrieved, regardless the quality
   * - Forwards any error from the translation api
   *
   * @param {string} text
   * @returns {Promise<string>}
   */
  free(text) {
    const obtenerTrad = this.api.fetch(text);
    return obtenerTrad.then(trad => trad.translation)
    
  
}


  /**
   * Batch translates the given texts using the free service.
   *
   * - Resolves all the translations (in the same order), if they all succeed
   * - Rejects with the first error that is encountered
   * - Rejects with a BatchIsEmpty error if no texts are given
   *
   * @param {string[]} texts
   * @returns {Promise<string[]>}
   */
  batch(texts) {
    return new Promise((res, rej) => {
      if (texts.length > 0) {
        const promises = texts.map((text) => this.api.fetch(text));
        
        Promise.all(promises).then((translations) => {
          res(translations.map((trad) => trad.translation));
        })
          .catch((error) => {
          rej(error);
        });
  };

  /**
   * Requests the service for some text to be translated.
   *
   * Note: the request service is flaky, and it may take up to three times for
   *       it to accept the request.
   *
   * @param {string} text
   * @returns {Promise<void>}
   */
 request(text) {
 
 }
  /**
   * Retrieves the translation for the given text
   *
   * - Rejects with an error if the quality can not be met
   * - Requests a translation if the translation is not available, then retries
   *
   * @param {string} text
   * @param {number} minimumQuality
   * @returns {Promise<string>}
   */
  premium(text, minimumQuality) {
    throw new Error('Implement the premium function');
  }

/**
 * This error is used to indicate a translation was found, but its quality does
 * not meet a certain threshold. Do not change the name of this error.
 */
export class QualityThresholdNotMet extends Error {
  /**
   * @param {string} text
   */
  constructor(text) {
    super(
      `
The translation of ${text} does not meet the requested quality threshold.
    `.trim(),
    );

    this.text = text;
  }
}

/**
 * This error is used to indicate the batch service was called without any
 * texts to translate (it was empty). Do not change the name of this error.
 */
export class BatchIsEmpty extends Error {
  constructor() {
    super(
      `
Requested a batch translation, but there are no texts in the batch.
    `.trim(),
    );
  }
}

Thank you very much for the lost time, sorry.

The return statement in free() lacks a semicolon. Could that be the issue?

No, I already tried, I don’t know what it could be.

    return new Promise((res, rej) => {

You never close the two brackets here.

These are function definitions btw - you used the correct terminology. They’re just defined in a class so look different.

There are two lessons here:

  1. That when asking for help, by sharing all your code (in a codeblock) at the start, people can more easily understand what’s going wrong. Often the error isn’t where you think it is and so screenshots and snippets of code tend to limit the person helping as they can’t see the bigger picture.

  2. Generally with esotoric errors (like this one), it suggests your code can’t be parsed, which often means you’ve made a typo somewhere before that line. So that’s how I’d approach debugging these things :slight_smile:

Wow, many thank you Jeremy , not only for the response now, if not for the whole project I love it I hope one day to be able to collaborate creating content for it.

Not only was I missing a bracket, I had a mess there I don’t know how it worked. It is costing me a lot the exercise of promises.

Greetings and keep it up, you and all the team are very great.

1 Like

Thank you for the kind words and the support :blue_heart: