-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprotostring.js
34 lines (32 loc) · 912 Bytes
/
protostring.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
String.prototype.replaceAll = function() {
var target = this;
return target.split(" ").join("-");
};
String.prototype.numberToString = function() {
var target = this;
var storing = "";
var strlength = target.length;
var numbers = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"];
for(var a = 0; a < strlength; a++) {
if(isNaN( target[a]) || target[a] == " ") {
storing += target[a];
}
else {
for(var i = 0; i < 10; i++) {
if(target[a] == i) {
storing += numbers[i];
}
}
}
}
return storing;
};
$(document).ready(function() {
$('button.hit').on('click',function() {
var convert;
var enteredstr = $('#data').val();
convert = enteredstr.numberToString();
var output = convert.replaceAll();
$('#converted').text(output);
});
});