I'm trying to build some programs for fun and learning. I have the problem below:
function Hero(name) {
this.name = name;
this.addItem = function(item) {
this.items = this.items || [];
this.items.push(item);
};
// ....
this.viewItinerary = function() {
this.items.map(function(currItem){
return currItem;
});
};
}
var alex = new Hero("Alex");
alex.addItem("Sword");
alex.addItem("Shield");
console.log(alex.viewItinerary());
// returns undefined. why does it not return items in array?
If I replace the return statement with a console.log(currItem) it works. So why is my code returning undefined? Any ideas?
Thanks