arrays - Javascript error: object is not a function in a video poker script -



arrays - Javascript error: object is not a function in a video poker script -

so have been writing script play video (or text-based) poker game exercise in learning javascript. have working play through instance of game once, on trying run sec time, develops error: "uncaught typeerror: object not function"

this error comes when trying create new hand.

here relevant code, left few functions out don't seem causing issues:

//object constructor card function card(suite, facevalue) { this.suite = suite, this.facevalue = facevalue } //object constructor hand function hand(cards, handname, score, dochandname) { this.cards = cards, this.handname = handname, this.score = score, this.dochandname = dochandname } var deck = new array; var builddeck = function() { (var = 0; <= 52; i++) { if (i < 13) { deck[i] = new card("spades", + 2); } else if (i < 26) { deck[i] = new card("clubs", - 11); } else if (i < 39) { deck[i] = new card("hearts", - 24); } else if (i < 52) { deck[i] = new card("diamonds", - 37); } } } //pulls card location in deck specified randomspot() var pullcard = function(spot) { var newcard = deck[spot]; deck.splice(spot, 1); homecoming newcard; } //takes away card each time //passes pullcard(spot) spot var pullcount = 0; var randomspot = function() { var x = math.floor(math.random() * (52 - pullcount)); pullcount++; homecoming x; } var dealfivecards = function() { var card1 = pullcard(randomspot()); var card2 = pullcard(randomspot()); var card3 = pullcard(randomspot()); var card4 = pullcard(randomspot()); var card5 = pullcard(randomspot()); var fivecards = [card1, card2, card3, card4, card5]; homecoming fivecards; } function createnewhand() { newhand = new hand(); newhand.cards = dealfivecards(); homecoming newhand; } var playonegame = function() { builddeck(); hand = createnewhand(); hand.cards.sort(compare); assignhandscore(); wager = prompt("how much bet?"); printhandvalue(); dealagain(); hand.cards.sort(compare); assignhandscore(); payout = pays(wager); printhandvalue(); printpayout(); } playagain = "y"; while (playagain === "y") { playonegame(); playagain = prompt("would play again? y/n").touppercase(); }

so error occurs when trying run playonegame() function sec time. first time runs fine , hand created. sec time when gets hand = createnewhand(); gives object not function error.

to clear, have hand created object, contains properties cards, handname, score, dochandname cards array of card objects, containing properties of suite, facevalue.

the error gives line newhand = new hand(); in function createnewhand() reference line.

help?

the sec line of playonegame overriding global hand function instance of hand. when createnewhand runs 1 time again hand no longer same thing.

you should rename function hand hand.

javascript arrays object

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -