Complete the code to define a class with a constructor in LLD.
class User { constructor([1]) { this.name = name; } }
The constructor parameter should be name to assign it to this.name.
Complete the code to add a method that returns the user's name.
class User { constructor(name) { this.name = name; } getName() { return this.[1]; } }
The method should return the name property of the object.
Fix the error in the code to correctly implement a setter method for the user's age.
class User { constructor(name) { this.name = name; this.age = 0; } setAge([1]) { this.age = age; } }
The parameter name must be age to match the assignment this.age = age;.
Fill both blanks to create a method that returns a formatted string with the user's name and age.
class User { constructor(name, age) { this.name = name; this.age = age; } getInfo() { return `$[1] is $[2] years old.`; } }
this inside class methods.The template string should use this.name and this.age to access the object's properties.
Fill all three blanks to implement a method that updates the user's name and age only if the new values are valid.
class User { constructor(name, age) { this.name = name; this.age = age; } updateUser([1], [2]) { if (typeof [3] === 'string' && [2] > 0) { this.name = [1]; this.age = [2]; } } }
The method parameters should be newName and newAge. The type check uses newName to verify the string.