<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!!
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(','));