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.
Question
- 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.
Solution
Sure, here is how you can define the function and the interface in TypeScript:
First, let's define the interface:
interface PrintTeacherFunction {
(firstName: string, lastName: string): string;
}
This interface defines a function type that takes two strings as arguments and returns a string.
Next, let's define the function:
const printTeacher: PrintTeacherFunction = (firstName, lastName) => {
return `${firstName[0]}. ${lastName}`;
}
This function takes two arguments, firstName and lastName, and returns a string that consists of the first letter of the firstName, a dot, a space, and the full lastName.
Now, you can use the function like this:
console.log(printTeacher("John", "Doe")); // Outputs: J. Doe
Similar Questions
Generate a list of the Instructor names by combining "Professor " and the first name, 1 space, and last name togethe
What is missing from the following code, to work with the function?student(name,class): print(f"my name is {name}, I am in class {class}")student("udin","TI22A")AstringsBdefCprintDcolon
Write a function that prints My name is <first name> <last name>Prototype: def say_my_name(first_name, last_name=""):first_name and last_name must be strings otherwise, raise a TypeError exception with the message first_name must be a string or last_name must be a stringYou are not allowed to import any module
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
Use a work sample to document a child’s ability to print her name.TrueFalse
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.