+ 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
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);
+ 4
Sheldon 10110 Ok, I can see now.
+ 1
Kevin ★ thanks a lot ..I get it now
0
Oops sorry.....forgot to link it....there it is
0
I have linked it