Need help using "arguments" to capture multiple elements to add all of the prices

var Games = function () { }; = {
    _gameTitle: ['Killzone 2', 'Halo 3', 'Uncharted 3', 'Gran Turismo 5', 'Modern Warfare 2', 'Final Fantasy XIII-2'], //List of games will be used
    _prices: [34.01, 17.99, 23.99, 29.37, 24.34, 21.81], //Prices for the "_gameTitle"

    searchGame: function (searchGames) { //The searchGame() function will be used to find the "_gameTitle" property.

        var gameMAX = this._gameTitle.length; //Cache the length of the "_gameTitle" property.

        for (var i = 0; i < gameMAX; i++) { //I will be using a for-loop to loop through the length of "gameMAX".

            if (searchGames === this._gameTitle[i]) { //Checks if searchGames matches any elements within the "_gameTitle" array property.

                return searchGames + ' is found'; //Will return true.
        return searchGames + ' is not found'; //Otherwise the value will return false.
    findPrice: function (getPrice) {

        //priceMAX and gameMAX will be used to cache data.
        var priceMAX = this._prices.length,
            gameMAX = this._gameTitle.length;

        //Will be looping through the length of _prices.length to compare the price.
        for (var x = 0; x < priceMAX; x++) {
            if (getPrice === this._gameTitle[x]) { //Checks if getPrice matches any elements within the "_gameTitle" array property.
                return 'The price for ' + getPrice + ' is: ' + this._prices[x]; //Statement will be true.
        return getPrice + ' is not found'; //Otherwise the value will be false.
    buyGames: function () {
        //Prepared the variables to be used in this method.
        var args = arguments.length,
            total = 0,
            games = this._gameTitle,
            prices = this._prices,
            a = 0;

        /*This is where I'm having difficulties trying to use multiple game titles to add up all of the prices for them by using
          arguments as my solution.
        for (; a < games.length; a++) { //Loop through the length of games property.
            for (var x = 0; x < args; x++) {
                if (arguments[x] === games[x]) {
                    arguments[x] = prices[x];
                    total += arguments[x];
        return total;

var result = new Games();'Killzone 2');

The code inside “buyGames” method only recognize the first element inside the “games” array. But won’t let me add up the total price with the other elements. I’m having difficulties trying to concatenate my “total” with the number of elements inside the “prices” array.

I want to have the ability to pick the “games” I want and let the “total” variable add up the cost.

Much appreciated,


You’re going to want to use two different loops. An outer loop that loops through each of the arguments, and an inner loop that loops through the available games checking for a match.

It works now. Thanks