-
Notifications
You must be signed in to change notification settings - Fork 1
/
piglatin.js
29 lines (28 loc) · 898 Bytes
/
piglatin.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
// why you no work?!
// version one
var response = prompt('Hmm whatchu say?');
if (isNaN(response)) {
var responseVowels = ['a', 'e', 'i', 'o', 'u'];
var responseFirst = response.charAt(0);
var responseRest = response.substring(1, -1);
if (responseVowels.contains(responseFirst)) {
var responseWay = response + 'way';
} else {
var responseWay = responseRest + responseFirst + 'ay';
}
alert(responseWay);
}
// version two made using skillcrush's hint
var response = prompt('Hmm whatchu say?');
if (isNaN(response)) {
var responseVowels = ['a', 'e', 'i', 'o', 'u'];
var responseFirst = response.toLowerCase().subString(0, 1);
var responseRest = response.toLowerCase().substring(1);
var responseIndex = responseVowels.indexOf(responseFirst);
if (responseIndex >= 0) {
var responseWay = response + 'way';
} else {
var responseWay = responseRest + responseFirst + 'ay';
}
alert(responseWay);
}