1

My Current Project

I am trying to make a terminal-style webpage using jQuery Terminal.

My Problem

I cannot figure out how to add more than one command to the terminal.

Here's my code:

$('body').terminal({
      hello: function(name) {
          this.echo('Hello, ' + name +
                    '. Welcome to the Rapocrythia command line.');
      }
  }, {
      greetings: 'Rapocrythia Command Line[Version 0.0.1]\n(c) Copyright Rapocrythia Systems, Inc. All Rights Reserved.'
  }
);
2
  • 1
    There are lots of jquery terminal plugins, do you have a link to the documentation of the one you're using? Commented Jul 22, 2020 at 16:17
  • Here's the docs. Commented Jul 22, 2020 at 19:13

1 Answer 1

1

Just add more properties to the first argument.

$('body').terminal({
  hello: function(name) {
    this.echo('Hello, ' + name +
      '. Welcome to the Rapocrythia command line.');
  },
  add: function(num1, num2) {
    this.echo(parseInt(num1) + parseInt(num2));
  },
  bye: function() {
    this.echo('So long');
  }
}, {
  greetings: 'Rapocrythia Command Line[Version 0.0.1]\n(c) Copyright Rapocrythia Systems, Inc. All Rights Reserved.'
});
<link href="https://unpkg.com/jquery.terminal/css/jquery.terminal.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://unpkg.com/jquery.terminal/js/jquery.terminal.min.js"></script>

If you type add 10 15 it will print 25.

Sign up to request clarification or add additional context in comments.

1 Comment

You don't need to use parseInt on arguments, jQuery Terminal is parsing numbers by default.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.