+ 1
Trying simple code, pls help
Can't find what's the problem while coding this: https://code.sololearn.com/WBsFI4auVvN4/?ref=app Update: code's been updated , works now ☝️
6 Respostas
+ 1
Justus
calculateAge is a function
if we do
this.age = calculateAge()
we are assigning a number to this.age
if we do
this.age = calculateAge
we are assigning a function to this.age
see?
+ 2
This.age = calculateage
You forgot to add () to make it a method
this.age =calculateage()
0
Thanks . But guys, do you know why in the another code there are no brackets and it still works
https://code.sololearn.com/WT2HqEp117QH/?ref=app
0
In the first example "bouncy", you executing the function and calculated a value to store in this.age
In the second example "bouncer works", you are assigning a function to this.age as class method
https://code.sololearn.com/W8p2a2xg3W5w/?ref=app
and so later, you call the age method with p.age() at your line 16 to execute it.
0
Gordon that line runs without the parenthesis too. But printing the value without the parenthesis won't work. Any explanation..
0
Keep coding , trying with if ..else , so error , anyone?
https://code.sololearn.com/WBsFI4auVvN4/?ref=app