initializing single object with function | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

initializing single object with function

https://sololearn.com/coach/609/?ref=app not sure how To CaLL VaIABLES In SiNGLE OBJECT INITIALIZATIoN

2nd Feb 2021, 2:24 PM
alex
4 Answers
+ 2
Your function has no return statement. And you should use `this` instead of `cuboid`. Also, parantheses are needed to call a function. It is cuboid.func() not cuboid.func. Lastly, it is not a class. It is an object. https://code.sololearn.com/Wjrp01lHlq6S/
2nd Feb 2021, 5:30 PM
Ore
Ore - avatar
+ 1
alex You can access properties from object in two ways: 1 - cuboid["length"] 2 - cuboid.length
2nd Feb 2021, 4:20 PM
A͢J
A͢J - avatar
+ 1
thanks!
2nd Feb 2021, 6:40 PM
alex
0
to clerify, i am trying to call the value within a module of the class. i try using ‘this’ as well as the name if the class but with mo results var cuboid = { length: 25, width: 50, height: 200, func: function (func) {cuboid.length * cuboid.width * cuboid.height}; //return this.length * this.width * this.height; }; var x = cuboid.func console.log(x);
2nd Feb 2021, 4:25 PM
alex