The code you've posted above doesn't look 100% correct to me. The idea of the Tut's tutorial, I'm assuming, is to teach you Javascript Object Oriented Programming basics.
I've created a commented JSfiddle here, using your above example. I hope this helps a little bit to answer your question.
https://jsfiddle.net/iamjpg/vtndfL1y/
Here is the JS inside the above fiddle:
// Define function which will be our Object
function cart(name) {
// Define a name for cart. Default to 'Bob' if undefined.
this.name = name || 'Bob';
// addToCart method on object.
this.addToCart = function(price) {
// If there is no total, set the total to zero.
if (!this.total) {
this.total = 0;
}
// Increment total by passed in price parameter
this.total += price;
// Return the string containing the total value.
return this.name + '\'s cart total is £' + this.total;
}
}
// Construct cart object
var cart = new cart('Mario');
// Set event listener on the button.
document.getElementById('cart_button').onclick = function() {
// On each click, update the cart price incrementing by 5.
document.getElementById('price').innerHTML = cart.addToCart(5);
}