-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsyntax.js
80 lines (75 loc) · 2.99 KB
/
syntax.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
79
80
var a_an = function(string, noun){ //returns the indefinite article using the next word as string and noun as noun
if (noun[noun.length - 1] == 's') {
return '';
} else if (string[0] == 'a' || string[0] == 'e' || string[0] == 'i' || string[0] == 'o' || string[0] == 'u' ||
string[0] == 'A' || string[0] == 'E' || string[0] == 'I' || string[0] == 'O' || string[0] == 'U') {
return 'an ';
} else {
return 'a ';
}
}
var a_ex = function(noun){ //returns an indefinite article depending on the plurality of the noun
if (noun[noun.length - 1] == 's') {
return '';
} else {
return 'a ';
}
}
var verb_plr = function(verb, noun) { //returns the verb with an s after it if the subject is singular
if (noun[noun.length-1] != 's') {
return verb + 's';
} else {
return verb;
}
}
var verb_cap = function(verb) {
var firstLetter = verb[0].toUpperCase();
var rest = verb.slice(1,verb.length);
return firstLetter + rest;
}
var a_an_noun = function(noun) {
if (noun[noun.length - 1] == 's') {
return '';
} else if (noun[0] == 'a' || noun[0] == 'e' || noun[0] == 'i' || noun[0] == 'o' || noun[0] == 'u' ||
noun[0] == 'A' || noun[0] == 'E' || noun[0] == 'I' || noun[0] == 'O' || noun[0] == 'U') {
return 'an ';
} else {
return 'a ';
}
}
var makeQuote = function() {
var tempUse = templates[Math.floor(Math.random()*templates.length)];
var quote = "";
var randomWords = [];
for (i = 0; i < tempUse[0].length; i++) {
switch(tempUse[0][i]) {
case 1: randomWords.push(adjectives[Math.floor(Math.random()*adjectives.length)]); break;
case 2: randomWords.push(adverbs[Math.floor(Math.random()*adverbs.length)]); break;
case 3: randomWords.push(nouns[Math.floor(Math.random()*nouns.length)]); break;
case 4:
var verb;
do {
verb = verbs[Math.floor(Math.random()*verbs.length+1)];
} while (verb[verb.length-1] == 'd' || verb[verb.length-1] == 's' ||
(verb[verb.length-3] == 'i' && verb[verb.length-2] == 'n' && verb[verb.length-1] == 'g'))
randomWords.push(verb);
break;
default: console.log("Wrong Expression (Assign)");
}
}
var pointer = 0;
for (j = 1; j < tempUse.length; j++) {
switch(tempUse[j]) {
case 1: case 2: case 3: case 4: quote += randomWords[pointer]; pointer++; break;
case 5: quote += a_an(randomWords[pointer],randomWords[pointer+1]); break;
case 6: quote += a_ex(randomWords[pointer]); break;
case 7: quote += verb_plr(randomWords[pointer],randomWords[pointer+1]); break;
case 8: quote += verb_cap(randomWords[pointer]); pointer++; break;
case 9: quote += a_an_noun(randomWords[pointer]); break;
default: quote += tempUse[j];
}
}
var response = randomWords;
response.push(quote);
return response;
}