-
Notifications
You must be signed in to change notification settings - Fork 0
/
generator.js
49 lines (49 loc) · 1.33 KB
/
generator.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
/**
* Question answer module.
*/
/**
* Array of search target string.
*/
var targets = [
'自經區', '自貿區',
'摩天輪', '愛情摩天輪', '愛情產業鏈',
'發大財', '愛河的水', '選總統',
'迪士尼',
'F1', 'F1賽車場', 'F1 賽車場',
'賭馬', '賽馬',
'九二共識', '一中各表', '一國兩制', '兩岸統一',
];
/**
* Search target in query string and return a tuple [isFound, foundTarget].
* @param query
*/
function checkWhats(query) {
for (var _i = 0, targets_1 = targets; _i < targets_1.length; _i++) {
var searchTarget = targets_1[_i];
if (query.indexOf(searchTarget) != -1) {
return [true, searchTarget];
}
}
return [false, null];
}
/**
* Check input string and return answer.
* @param word
*/
function sayFadachia(word) {
var returnTup = checkWhats(word);
if (returnTup[0]) {
return '總目標是高雄要發大財, 這個' + returnTup[1] + '只是其中一部份, 好不好? 謝謝.';
}
else {
return '你說的不是重點, 重點是高雄要發大財.';
}
}
/**
* Button event handler.
*/
function btnSayFadachia() {
var inputText = document.getElementsByName('word')[0].value;
console.log(inputText);
document.getElementsByName('fadachia')[0].innerText = sayFadachia(inputText);
}