javascript - Uncaught Typeerror: Cannot read Property 'Odd' of Undefined

Asked

Viewed 737 times

0

Hello!

In my Javascript code I get the following error:

"Uncaught Typeerror: Cannot read Property 'Odd' of Undefined"

Since I’m new in the area, I don’t quite understand how to solve the problem, you can help me ?

case 'multiple_2_3':

    total = 3 * self.card.quantity;
    $("#resume-odds").hide();
    //gains = (cota1 * cota2) * self.card.quantity + (cota1 * cota3) * self.card.quantity +  (cota2 * cota3) * self.card.quantity
    for (let i in self.card.bets) {
        let bet1 = self.card.bets[i];
        if(self.card.bets.length > i){
        for (let j = i + 1; j < self.card.bets.length; j++) {
            let bet2 = self.card.bets[j];
            gains += parseFloat(bet1.odd) * parseFloat(bet2.odd) * self.card.quantity;
        }
        }
    }

    break;
case 'multiple_2_4':
    total = 6 * self.card.quantity;
    $("#resume-odds").hide();

    for (let i in self.card.bets) {
        let bet1 = self.card.bets[i];
        for (let j = i + 1; j < self.card.bets.length; j++) {
            let bet2 = self.card.bets[j];
            gains += parseFloat(bet1.odd) * parseFloat(bet2.odd) * self.card.quantity;
        }
    }

    break;

1 answer

1


That mistake means that bet1 has no defined value. That is, when do let bet1 = self.card.bets[i]; the object or array .bets has no value to the property i (or has value and he is undefined).

Once you have if(self.card.bets.length > i){ before, this ensures that the i is not larger than the array, which is good, but indicates that the position i of that array is undefined. That’s where you have to look for the problem and figure out why it happened. This will be another question maybe but review how you build this array and where the values come from.

  • I have already reviewed and seem to me rights , he in the first for has values in the second is that it seems to lose them

  • @Joana if you haven’t solved the problem do a jsFiddle that plays what you have that I take a look and help.

  • my code is too big and has several.js files and all interconnected to just pull this , I can give the link of the site and can see find on the console and this

  • @Joana ok, put the link to see if it can help

  • is this, thank you https://projectos.epcjc.net/~i15575/pap_joana1/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.