var calculator = { read : function(){ var sumOne = prompt('enter one number', ''); console.log(sumOne); }; calculator.read(); console.log(calculator.read.sumOne); 

How to output sumOne to the console not in the object.

    1 answer 1

    sumOne is a local variable in the function that cannot be accessed from outside. But it can be returned from the function:

     var calculator = { read: function() { var sumOne = prompt('enter one number', ''); return sumOne; } }; var number = calculator.read(); console.log(number); 

    • 2
      If you need to do what the author wants, then you need to return not just sumOne , but an object with the option sumOne . Those. return {sumOne: sumOne} . As a result, calculator.read().sumOne will be called. This is in addition to your answer - Vasily Barbashev