-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwordnik.js
More file actions
56 lines (34 loc) · 1.09 KB
/
wordnik.js
File metadata and controls
56 lines (34 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
$(document).ready(function(){
function getRandomWord(callback){
$.ajax({
url: "http://api.wordnik.com/v4/words.json/randomWords?hasDictionaryDef=true&minCorpusCount=0&minLength=5&maxLength=15&limit=1&api_key=a2a73e7b926c924fad7001ca3111acd55af2ffabf50eb4ae5"
}).done(function(data) {
console.log('api success:');
console.log(data);
console.log(data[0].word);
callback(data[0].word);
});
}
$('#NewWord').click(function(){
getRandomWord(function(randWord){
$('#wordAppend').empty();
$("#wordAppend").append(randWord + ":");
// call getdefiniotion function with word as param
console.log('27');
getDefinition(randWord, function(text){
$('#defAppend').empty();
$('#defAppend').append(text);
});
});
});
function getDefinition(word,callback){
console.log('44');
$.ajax({
url: "http://api.wordnik.com/v4/word.json/"+word+"/definitions?api_key=a2a73e7b926c924fad7001ca3111acd55af2ffabf50eb4ae5"
}).done(function(data) {
console.log('api success: definition');
console.log(data);
callback(data[0].text);
});
}
});