+ 1

What is wrong with this piece of code?

It's supposed to print out either high or low danceability but it prints out the method code??? https://code.sololearn.com/WZP30hEO8lkg/?ref=app

27th Sep 2020, 8:38 PM
Sheldon 10110
Sheldon 10110 - avatar
5 odpowiedzi
+ 3
Because you are assigning the function itself and not its result. In order to use the result of the function you need to call it. Your function needs to return the danceability instead of changing it directly, otherwise the ruturned value will be undefined. function song(tempo){ this.tempo=tempo; this.danceability=danceness(this.tempo); //passing the tempo so we can use it in the function } function danceness(tempo) { if(tempo>130){ return "high"; } else { return "low"; } } var dontgo= new song(140); document.write(dontgo.danceability);
27th Sep 2020, 9:05 PM
Kevin ★
+ 4
Sheldon 10110 Ok, I can see now.
27th Sep 2020, 8:44 PM
Kevin ★
+ 1
Kevin ★ thanks a lot ..I get it now
28th Sep 2020, 9:15 AM
Sheldon 10110
Sheldon 10110 - avatar
0
Oops sorry.....forgot to link it....there it is
27th Sep 2020, 8:47 PM
Sheldon 10110
Sheldon 10110 - avatar
0
I have linked it
27th Sep 2020, 8:50 PM
Sheldon 10110
Sheldon 10110 - avatar