I have a function: I need to know from Wiktionary API if a user´s input german noun / adjective exists and its grammatical gender.
But the function always returns undefined although:
- I asked for a return
- the function is async
- I used .onload on the function call waiting for the response
Could you please explain me what I am doing wrong? It´s the first time I work with APIs and I am pretty confused.
Thanks
check(userInput).onload;
async function check(word) {
$.getJSON('http://de.wiktionary.org/w/api.php?action=parse&format=json&prop=text|revid|displaytitle&callback=?&page=' + word,
function (json) {
try {
let variable = json.parse.text['*'];
let nounM = variable.search('id=\"Substantiv,_m\">');
let nounF = variable.search('id=\"Substantiv,_f\">');
let nounN = variable.search('id=\"Substantiv,_n\">');
let adjective = variable.search("href=\"#Adjektiv");
let gender = Math.max(nounM,nounF,nounN,adjective);
console.log(gender);
return gender;
} catch (e) {
console.log(e);
return undefined;
}
});
};