-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdecodeMessage.js
98 lines (90 loc) · 1.98 KB
/
decodeMessage.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
var mode = 'upperCase';
var decodeAMessage = function() {
var message = prompt('Type in your message. Use commas to separate characters.');
var number = message.split(',');
var decodeMessage = '';
for (var i = 0; i < number.length; i++) {
var intGroup = parseInt(number[i]);
decodeMessage += modeSwitch(intGroup);
};
alert('Here is your message: ' + decodeMessage);
};
var numberToUpperCase = function(number) {
var outputUpperCase = String.fromCharCode(number + 64);
return outputUpperCase;
};
var numberToLowerCase = function(number) {
var outputLowerCase = String.fromCharCode(number + 96);
return outputLowerCase;
};
var numberToPunctuation = function(number) {
var outputPunctuation = '';
switch (number) {
case 1:
outputPunctuation = '!';
break;
case 2:
outputPunctuation = '?';
break;
case 3:
outputPunctuation = ',';
break;
case 4:
outputPunctuation = '.';
break;
case 5:
outputPunctuation = ' ';
break;
case 6:
outputPunctuation = ';';
break;
case 7:
outputPunctuation = '"';
break;
case 8:
outputPunctuation = "'";
break;
default:
alert('No such number.');
break;
}
return outputPunctuation;
};
var modeSwitch = function(number) {
var char;
switch (mode) {
case 'upperCase':
if (number % 27 === 0) {
mode = 'lowerCase';
return '';
} else {
char = numberToUpperCase(number % 27);
return char;
char = '';
break;
}
case 'lowerCase':
if (number % 27 === 0) {
mode = 'punctuation';
return '';
} else {
char = numberToLowerCase(number % 27);
return char;
char = '';
break;
}
case 'punctuation':
if (number % 9 === 0) {
mode = 'upperCase';
return '';
} else {
char = numberToPunctuation(number % 9);
return char;
char = '';
}
break;
}
};
// #!/user/bin/env node = ./file
// console.log(function(process.argv[2]))
decodeAMessage();