Home > Net >  JavaScript- making lists and more
JavaScript- making lists and more

Time:07-02

Given the following assignment:

In JavaScript, you want to manage a list of exam registrations. To do this, it is necessary to create the Enrollment function, which acts as a constructor of the Objects of type Enrollment: these objects are characterized by a code, the date, the name of the teaching, the student's serial number from the date of the appeal. In addition, the PDP practice number (if the student has a recognized PDP) can be specified for an enrollment. Then create the SubscriptionList function, which acts as a constructor of objects that manage collections of inscriptions. A collection provides the following methods: addSubscription (which receives the Subscription object to be inserted), get (which receives the subscription code to be returned), and drop (which receives the subscription code to be deleted from the collection). This is what I have done for the first part:

function Inscription(code, date, subject, studentId, dateOfExam)

this.code= code;
this.date= date; 
this.subject = subject;
this.studentId = studentId;
this.dateOfExam = dateOfExam;

var MyList = new Array(); 
my.Inscription(new inscription( "W123", "010722", "JavaScript", "8410" , "010722"));

not sure about the rest thanks in advance

CodePudding user response:

You started good, although the code you provided doesn't compile. let's fix that:

// added PDP
function Inscription(code, date, subject, studentId, dateOfExam, PDP) {
  this.code = code;
  this.date = date;
  this.subject = subject;
  this.studentId = studentId;
  this.dateOfExam = dateOfExam;
  this.PDP = PDP;
}

// var MyList = new Array();
// my.Inscription(new inscription("W123", "010722", "JavaScript", "8410", "010722"));
// this makes more sense: (note lower case upper case)
var inscription = new Inscription("W123", "010722", "JavaScript", "8410", "010722");
// anoher one:
var other_inscription = new Inscription("W124", "010722", "JavaScript 2", "8411", "010722");
// btw - why didn't you call it Enrollment?

// ok next is the SubscriptionList function 
function SubscriptionList() {
  var private_arr = []; // !

  // has the following methods:
  this.addSubscription = function(subscription) {
    private_arr.push(subscription);
  }

  this.get = function(subscription_code) {
    // ...
  }

  this.drop = function(subscription_code) {
    // ...
  }

  // let's add one more!
  this.toString = function() {
    return JSON.stringify(private_arr, null, 4)
  }
}

// new you can
var subscriptionList = new SubscriptionList();
subscriptionList.addSubscription(inscription);
subscriptionList.addSubscription(other_inscription);
subscriptionList.drop("W123");

console.log(subscriptionList.toString())
// good luck.
.as-console-wrapper {
  max-height: 100% !important;
}

  • Related