Solution 1 :

You should correct your code like this

var value = async() => {
    const input = $("#input").val();
    try {
        const response = await fetch(
        `https://wordsapiv1.p.rapidapi.com/words/hatchback/typeOf?location=` + input, {
            method: 'GET',
            headers: {
                'X-RapidAPI-Host': 'wordsapiv1.p.rapidapi.com',
                'X-RapidAPI-Key': '6bf945be36msh9deedbbf5135343p16d366jsnd17d03ee5bd4'
            }
        })

        const jsonResponse = response.json();
        alert(`${jsonResponse}`)

    } catch (error) {
        console.log(error);
    }
}

Couple things you were missing the : before headers declaration and the input selector was wrong

Solution 2 :

It seems that the input selector is missing the ' and #.
Your input has the an ID with the value input

This wont work because it tries to select an element with by the value of input

const input = $(input);

Here we select and element with the ID (#) input (#input)

const input = $('#input');

And to get the value of the element simply use .val()

const input = $('#input').val();

Problem :

Hey i can’t understand why this isn’t working. I’m getting two errors. The first is that value isn’t a function and the second is that the ‘{‘ after “catch(error)”, is an unexpected error. I don’t get the ‘{‘ error, when i add the javascript directly into my html though.Thanks for any help. The script is wrapped in script but it messes with the code block when i enter it.

const value = async() => {

const input = $(input);
try{
    const response = await fetch(`https://wordsapiv1.p.rapidapi.com/words/hatchback/typeOf?=${input}`, {
      method: 'GET',
      headers{
          'X-RapidAPI-Host': 'wordsapiv1.p.rapidapi.com',
          'X-RapidAPI-Key': '6bf945be36msh9deedbbf5135343p16d366jsnd17d03ee5bd4'
      }
    })
    
    const jsonResponse = response.json();
    alert(`${jsonResponse}`)

} catch(error) {
    console.log(error);
}
}; 




<input type="text" placeholder="enter location" id="input">
<button onclick="value()"></button>

Comments

Comment posted by OldProgrammer

you really should not post your application keys in questions.

Comment posted by Synapsis

You’re missing the : after headers

Comment posted by HighlandRocket

Don’t worry, it’s a generic api, that everyone has access to. Thank you though

Comment posted by HighlandRocket

Thank you so much! That will be why it keeps detecting ‘{‘ as an incorrect input! Also having # completely missed me in my learning. Absolute legend, thank you!

Comment posted by Synapsis

@HighlandRocket no problem man!! Good to hear that it worked. Please assign this as the correct answer so that other people can read the solution to this problem

Comment posted by HighlandRocket

Thank you a million! I’ve spent so long learning intermediate topics, that i’ve missed a few things from my earlier topics!. You’re amazing, sorry i can’t upvote yet!

By