1

I'm new to using APIs, I think I am doing something wrong. I'm trying to return translated text from the Oxford Dictionary API:

translateBtn.addEventListener("click", () => {
    let text = fromText.value.trim(),
    translateFrom = selectTag[0].value,
    translateTo = selectTag[1].value;
    let app_id = "xxxxxxxx";
    let app_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
    let language = "en-gb";
    let word_id = "example";
    let apiUrl = 'https://od-api.oxforddictionaries.com/api/v2/entries/${language}/${word_id}';

    fetch(apiUrl, {
        method: "GET",
        mode: "no-cors",
        headers: { app_key: app_key, app_id: app_id },
        })
        .then((response) => response.json())
        .then((data) => res.send(data));
}); 

I am getting the following error when I run this code. Have I done something incorrect? Thanks in advance!

enter image description here

redPine
  • 21
  • 1
  • 1
    You are using regular quotes for `let apiUrl = ` but you need to use **backticks** because you are using string interpolation syntax. For more info, see [Template literals on MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals). I can't tell if that is the only problem or not, but it sure is one step closer. – Peter B Oct 12 '22 at 22:59
  • `mode: 'no-cors'` will ensure you will never be able to read the response too – Phil Oct 12 '22 at 23:13

0 Answers0