Skip to content
Advertisement

How to Make a Log Retrieval System with jQuery Terminal

My Current Project

I’m trying to make a terminal with jsQuery that has a log retrieval function.

My Problem

I don’t know how to

  1. Make the function use an argument instead of writing each command, one by one.

Here’s my code:

RETRIEVE 1: function() {
    this.echo('Log one.');
  },
RETRIEVE 2: function() {
   this.echo('Log two.);
  }

Advertisement

Answer

As I understand what you need is object, key values pair:

I used object instead of array, because they don’t need to be in order and some number may be missing.

var log = {
  1: 'Log one.',
  2: 'Log two.'
};

$('body').terminal({
    RETRIEVE: function(logNumber) {
       this.echo(log[logNumber]);
    }
});
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement