I did it, but why it's undefined?


#1

https://www.codecademy.com/courses/javascript-beginner-en-6LzGd/1/1?curriculum_id=506324b3a7dffd00020bf661

I did this exercise, but it doesn't shows the result, it shows "undefined", why?


var orange = 5;
function orangeCost(){
  var val = orange * 5;  
};

console.log(orangeCost());


#2

The function has no return value, so JavaScript reports it as undefined. Your function should take a parameter, not use a global variable.

function orangeCost(price) {
    return ...
}
console.log(orangeCost(5));

#3

Ok, now I understand


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.