-
Notifications
You must be signed in to change notification settings - Fork 0
/
HQ9P.js
31 lines (29 loc) · 1.05 KB
/
HQ9P.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
function interpreter(command) {
let out = "";
let number = 0;
for (let n = 0; n < command.length; n++) {
if (command[n] === "h" || command[n] === "H") {
out += "Hello World.\n";
} else if (command[n] === "q" || command[n] === "Q") {
out += command + "\n";
} else if (command[n] === "9") {
for (let i = 99; i >= 0; i--) {
if (i === 0) {
// Do nothing
} else if (i === 1) {
out += "1 bottle of beer. \nTake one down and pass it around, \nno more bottles of beer on the wall.\n\n";
} else {
out += `${i} bottle of beer. \nTake one down and pass it around, \n${i - 1} bottles of beer on the wall.\n\n`;
}
}
} else if (command[n] === "+") {
number += 1;
} else {
return "--- EXCEPTION:\nunexpected characters found in source code.\n";
}
}
return out;
}
while (true) {
console.log(interpreter(prompt(">>> ")));
}