Home > OS >  ask from the command prompt to input data to all the entities, and it should give the option to add
ask from the command prompt to input data to all the entities, and it should give the option to add

Time:12-19

<script>
  class Course {
    constructor(title, stream, type, start_date, end_date) {
      this.title = title;
      this.stream = stream;
      this.type = type;
      this.start_date = start_date;
      this.end_date = end_date;
      }
   }                                                                                                                                                                                                                                                                                        
  let newCourseInstance = new Course(
    window.prompt("Title:"),
    window.prompt("Stream:"),
    window.prompt("Type:"),
    window.prompt("Start date:"),
    window.prompt("End date:")
    );

Hello everyone!! i just want to ask something about an assignment that i should do. The application must ask from the command prompt to input data to all the entities, and it should give the option to add more than one entry at a time. Do you know how to do this iterration? Thank you for your time!!

CodePudding user response:

You can declare all the entities you want in an array and iterate this one and pass it to the class constructor.

      class Course {
        constructor(title, stream, type, start_date, end_date) {
         this.title = title;
         this.stream = stream;
         this.type = type;
         this.start_date = start_date;
         this.end_date = end_date;
       }
     }   

    const entities = ["Title:","Stream:","Type:","Start date:","End date:"]
    const data = entities.map(d => window.prompt(d))
    let newCourseInstance = new Course(data.join(',')); 

CodePudding user response:

Thank you for your feedback! But how can the iteration be if the user wants to do more than one entry in the course? I should ask if user wants to add another course and then continue.

  • Related