+ 1

What is the wrong with this code?

function person(name,age,color) { this.name = name; this.age = age; this.color = color; }; var p1 = new person("Sam",24,"blue"); var p2 = new person("Moshahed",25,"red"); var p3 = new person("Somrat",24,"green"); document.write(p1.name); document.write(p2.age); document.write(p3.color); Uncaught TypeError: person is not a constructor

20th Oct 2020, 5:29 AM
Moshahed Ullah
Moshahed Ullah - avatar
4 Answers
+ 2
Code runs just fine, I tested it in browser and SoloLearn app, no problem 🤔
20th Oct 2020, 5:49 AM
Ipang
+ 2
But when I run this code in my Google Chrome browser it says error
20th Oct 2020, 7:10 AM
Moshahed Ullah
Moshahed Ullah - avatar
+ 1
Can you explain how you are running the code in your browser? There are different steps to take to run it in browser.
21st Oct 2020, 4:43 AM
Chris Coder
Chris Coder - avatar
+ 1
Moshahed Somrat Tell me what error message is?
21st Oct 2020, 5:01 AM
Ipang