0

Why is this not recognised as a function

I am training to work with classes for a bit now, but I can't find out why sometimes this.doSomething is not recognised as a function. https://code.sololearn.com/WDfXd4NVBplu/?ref=app

8th Mar 2019, 11:59 PM
Roel
Roel - avatar
4 Answers
+ 4
The problem here is your making a new instance of the "num" class (good) but then your immediately calling the "toBinary" method on it so q is not a new instance of that class but the value that the used method returns. So, for example, if you input 119 q would be equal to: 1110111 (119 in binary) and of course, that number does not have the "isBinary" method hence the error message. Anyway, that's enough rambling for now 😅 here is the solution: https://code.sololearn.com/WkFCgRMOa3Pk/?ref=app
9th Mar 2019, 12:49 AM
LynTon
LynTon - avatar
+ 3
With the way you have it setup now, yes, that would change its x property to a binary number.
9th Mar 2019, 2:48 PM
LynTon
LynTon - avatar
+ 1
So what you're saying is in order to let q be a binary number (1110111) I would have to change the toBinary method from a returning method to a this.x = (this.x >>> 0).toString(2);
9th Mar 2019, 10:34 AM
Roel
Roel - avatar
0
Ok thanks!
9th Mar 2019, 8:59 PM
Roel
Roel - avatar