Skip to content

Commit 9395c98

Browse files
committed
codecrafters submit [skip ci]
1 parent e1e8b56 commit 9395c98

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

β€Žapp/main.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const readline = require("readline");
22

3-
const commands = ["exit"];
3+
const commands = ["exit", "echo"];
44

55
let terminal = true;
66

@@ -11,12 +11,16 @@ const rl = readline.createInterface({
1111

1212
const promptUser = () => {
1313
rl.question("$ ", (answer) => {
14-
const command = answer.split(" ")[0];
15-
if (!commands.includes(command)) {
16-
console.log(`${command}: command not found`);
17-
} else if (command === "exit") {
14+
const promptArray = answer.split(" ");
15+
const userCommand = promptArray[0];
16+
const userInput = promptArray.slice(1);
17+
if (!commands.includes(userCommand)) {
18+
console.log(`${userCommand}: command not found`);
19+
} else if (userCommand === "exit") {
1820
rl.close();
1921
process.exit(0);
22+
} else if (userCommand === "echo") {
23+
console.log(userInput.join(" "));
2024
}
2125
if (terminal) {
2226
promptUser();

0 commit comments

Comments
 (0)