2. Extending the Teacher classmandatoryWrite an interface named Directors that extends Teacher. It requires an attribute named numberOfReports(number)Example:const director1: Directors = { firstName: 'John', lastName: 'Doe', location: 'London', fullTimeEmployee: true, numberOfReports: 17,};console.log(director1);// should print// Object// firstName: "John"// fullTimeEmployee: true// lastName: "Doe"// location: "London"// numberOfReports: 17
Question
- Extending the Teacher classmandatoryWrite an interface named Directors that extends Teacher. It requires an attribute named numberOfReports(number)Example:const director1: Directors = { firstName: 'John', lastName: 'Doe', location: 'London', fullTimeEmployee: true, numberOfReports: 17,};console.log(director1);// should print// Object// firstName: "John"// fullTimeEmployee: true// lastName: "Doe"// location: "London"// numberOfReports: 17
Solution
The question is asking to create an interface named "Directors" that extends from another interface named "Teacher". This new interface should have an additional attribute named "numberOfReports" which is a number. Here is how you can do it in TypeScript:
interface Teacher {
firstName: string;
lastName: string;
location: string;
fullTimeEmployee: boolean;
}
interface Directors extends Teacher {
numberOfReports: number;
}
const director1: Directors = {
firstName: 'John',
lastName: 'Doe',
location: 'London',
fullTimeEmployee: true,
numberOfReports: 17,
};
console.log(director1);
In the above code, we first define the "Teacher" interface with the required attributes. Then we define the "Directors" interface that extends the "Teacher" interface and adds an additional attribute "numberOfReports". Finally, we create an object "director1" of type "Directors" and log it to the console.
Similar Questions
2. A Course, Getters, and SettersmandatoryImplement a class named HolbertonCourse:Constructor attributes:name (String)length (Number)students (array of Strings)Make sure to verify the type of attributes during object creationEach attribute must be stored in an “underscore” attribute version (ex: name is stored in _name)Implement a getter and setter for each attribute.bob@dylan:~$ cat 2-main.jsimport HolbertonCourse from "./2-hbtn_course.js";const c1 = new HolbertonCourse("ES6", 1, ["Bob", "Jane"])console.log(c1.name);c1.name = "Python 101";console.log(c1);try { c1.name = 12;} catch(err) { console.log(err);}try { const c2 = new HolbertonCourse("ES6", "1", ["Bob", "Jane"]);}catch(err) { console.log(err);}bob@dylan:~$ bob@dylan:~$ npm run dev 2-main.js ES6HolbertonCourse { _name: 'Python 101', _length: 1, _students: [ 'Bob', 'Jane' ]}TypeError: Name must be a string ...TypeError: Length must be a number ...bob@dylan:~$
1. Let's build a Teacher interfacemandatoryCreate a directory task_1 and copy these configuration files into this folder: package.json, tsconfig.json, webpack.config.jsfirstName(string) and lastName(string). These two attributes should only be modifiable when a Teacher is first initializedfullTimeEmployee(boolean) this attribute should always be definedyearsOfExperience(number) this attribute is optionallocation(string) this attribute should always be definedAdd the possibility to add any attribute to the Object like contract(boolean) without specifying the name of the attributeExample:const teacher3: Teacher = { firstName: 'John', fullTimeEmployee: false, lastName: 'Doe', location: 'London', contract: false,};console.log(teacher3);// should print// Object// contract: false// firstName: "John"// fullTimeEmployee: false// lastName: "Doe"// location: "London"
0. You used to attend a place like this at some pointmandatoryImplement a class named ClassRoom:Prototype: export default class ClassRoomIt should accept one attribute named maxStudentsSize (Number) and assigned to _maxStudentsSizebob@dylan:~$ cat 0-main.jsimport ClassRoom from "./0-classroom.js";const room = new ClassRoom(10);console.log(room._maxStudentsSize)bob@dylan:~$ bob@dylan:~$ npm run dev 0-main.js 10bob@dylan:~$
3. Printing teachersmandatoryWrite a function printTeacher:It accepts two arguments firstName and lastNameIt returns the first letter of the firstName and the full lastNameExample: printTeacher("John", "Doe") -> J. DoeWrite an interface for the function named printTeacherFunction.
4. Writing a classmandatoryWrite a Class named StudentClass:The constructor accepts firstName(string) and lastName(string) argumentsThe class has a method named workOnHomework that return the string Currently workingThe class has a method named displayName. It returns the firstName of the studentThe constructor of the class should be described through an InterfaceThe class should be described through an InterfaceRequirements:You can reuse the Webpack configuration from the previous exercise to compile the code.When running npm run build, no TypeScript error should be displayed.Every variable should use TypeScript when possible.
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.