12 Answers
New Answerhttps://code.sololearn.com/Wjfb0A8J88YF/?ref=app
5/15/2022 12:57:15 PM
Muhammad Awwal Yusuf12 Answers
New AnswerIn function, return this pointer. And then you use like this without new function Person(firstName,lastName,age,eyeColor) { this.firstName = firstName; this.lastName = lastName; this.age = age; this.eyeColor = eyeColor; return this; //return function pointer } const f = Person(firstName , lastName , age);
Yes. It works but create second object in same as first object. You are creating second object with previous first inputs, next changing through inputs. So father.age is same as mothers.age, instead of undefined because you given any value still. If not problem then, leave as it is..
//you are not setting Function values. And also you can't use out side function that way.. function Person(firstName,lastName,age,eyeColor) { this.firstName = firstName; this.lastName = lastName; this.age = age; this.eyeColor = eyeColor; } firstName =prompt("write first name"); lastName = prompt("Write last name"); age = prompt("Write your age"); var f = new Person(firstName ,lastName ,age); document.write("first name is " + f.firstName + " " +"and she is" + f.age + " years old");
Observe my reply carefully.. Try that, just copy and paste in your code. Run it and see.. Your object creation is still wrong.
Jayakrishna🇮🇳 can you check my code again, did I do everything right this time?
Sololearn Inc.
535 Mission Street, Suite 1591Send us a message