- 2

After giving the input why it shows error?

I know the right answer of js problem contact manager is :- function contact(name, number) { this.name = name; this.number = number; this.print=function() { console.log( this.name +":",this.number); } } var a = new contact("David", 12345); var b = new contact("Amy", 987654321); a.print(); b.print(); But, If i write :- Function contact(name,number){ this.name = name; this.number = number; this.print = go; } Function go(){ return this.name + ":" + '\xa0' + this.number; } var a = new contact("David", 12345); var b = new contact("Amy", 987654321); Console.log(a.print()); Console.log(b.print()); This also gave the same result David : 12345 Amy : 987654321 But it shows wrong.plz tell why it shows wrong

18th May 2021, 4:11 AM
Aurosish dev
Aurosish dev - avatar
1 Answer
+ 2
When Sololearn asks for output, they are usually asking for you to `console.log` something. Simply returning will not actually print the value, thus Sololearn reads this as no output. In the test cases, Sololearn will be undoubtedly creating different instances of `contact` and giving them different `name`s and `number`s and then running the `print` method of that instance to ensure you cannot simply print the correct string and have actually solved the challenge.
29th Jun 2022, 7:22 AM
Matthew James
Matthew James - avatar