-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLearnEnglish.js
78 lines (75 loc) · 2.43 KB
/
LearnEnglish.js
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
var givemeaningbtn, lang, partofspeech, definition;
$(document).ready(function() {
givemeaningbtn = $('#givemeaning');
lang = $('#lang')[0];
partofspeech = $('#partofspeech')[0];
definition = $('#def')[0];
givemeaningbtn.click(() => {
$('#loading').css('display', 'block');
$('#search').css('display', 'none');
let ttl = lang.textContent;
givemeaning(ttl);
})
})
function voice(text) {
responsiveVoice.speak(text, "UK English Female", {
rate: 0.92,
pitch: 0.93
});
}
// console.log = function() {}
// console.log = function() {
// return null;
// };
function shsp() {
$('#word').css('display', 'block');
$('#team').css('display', 'none');
lang.textContent = 'Spanish';
partofspeech.innerHTML = "";
definition.innerHTML = '';
}
function ws() {
$('#word').css('display', 'block');
$('#team').css('display', 'none');
lang.textContent = 'English';
partofspeech.innerHTML = "";
definition.innerHTML = '';
}
function team() {
$('#word').css('display', 'none');
$('#team').css('display', 'block');
}
// $.getJSON('https://dictionaryapi.com/api/v3/references/collegiate/json/' + word + '?key=2bb7ce61-85ed-49f4-9be2-0a78b5f5eda5', function(data) {
//$.getJSON('https://dictionaryapi.com/api/v3/references/spanish/json/' + word + '?key=316b8347-2b67-4672-9d33-c72e48e6a23f', function(data) {
function givemeaning(lang) {
let word = $('#st').val();
voice(word);
let apiurl = 'notfound'
if(lang == 'English') {
apiurl = 'https://dictionaryapi.com/api/v3/references/collegiate/json/' + word + '?key=2bb7ce61-85ed-49f4-9be2-0a78b5f5eda5';
} else if(lang == 'Spanish') {
apiurl = 'https://dictionaryapi.com/api/v3/references/spanish/json/' + word + '?key=316b8347-2b67-4672-9d33-c72e48e6a23f';
}
$.getJSON(apiurl, function(data) {
var c = data[0];
// alert(typeof(c));
try {
console.log(c, typeof(c))
var text = data[0].shortdef[0];
var f = data[0].fl;
voice(text);
definition.innerHTML = text;
partofspeech.innerHTML = f;
} catch (e) {
partofspeech.innerHTML = "Invalid Word";
definition.innerHTML = '';
} finally {
f = "";
text = "";
$('#loading').css('display', 'none');
$('#search').css('display', 'block');
}
//console.log(JSON.stringify(data[0].shortdef[0], null, 1));
//console.log(JSON.stringify(data[0].fl, null, 1));
});
};