0
var myCar2 = {

    maxSpeed: 70,
    driver: "Arnold",

    drive: function(speed, time) {
        console.log("speed " + (speed * time));
    },

    logbook: function(a , b) {      
        console.log("max speed " + this.maxSpeed + " " + this.drive(a , b));
    }
};

myCar2.logbook(3 , 6);

If I run that code this.drive(a , b) is undefined. How can i pass variables to drive() function using logbook()?

3
  • 2
    This should work just fine as is. The only thing is that you're not returning anything from drive, so its return value is undefined. Commented Apr 19, 2016 at 7:45
  • 1
    @Amit No. Just no. Commented Apr 19, 2016 at 7:46
  • yes i dont use return. Thank you now with return i get what i want. Commented Apr 19, 2016 at 7:50

1 Answer 1

7

You are passing variables to drive, and they are defined within it. If they weren't then you wouldn't get speed 18 in the output, you would get speed NaN.

The undefined value is the return value of drive, which is because you haven't put a return statement in that function.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.