ga-wdi-exercises / project1

[project] GA- Project 1
3 stars 75 forks source link

Function issues.... #70

Closed MikeDulik closed 9 years ago

MikeDulik commented 9 years ago

I am trying to write these 2 function, but am experiencing a bug issue with each during the initial setup of my BlackJack game...

// var deckLength = cards.length;
 // var valLength = values.length;
 // var index = 0;
 // index = Math.floor((Math.random() * deckLength) + 1);
deckInit(deckLength, valLength, i);

// var dealerCard1 = cards[index];
// var dealerVal1 = values[index];
// cards.splice(index, 1);
// values.splice(index, 1)
deckDeal(dealerCard1, dealerVal1, index, dealerTotal);```

```function deckInit( dLength, vLength, i){
  var dLength = cards.length;
  var vLength = values.length;
  var i = 0;
  i = Math.floor((Math.random() * dLength) + 1);
}

function deckDeal( card, val, i, total){
  var i = Math.floor((Math.random() * cards.length) + 1);
  var card = cards[i];
  var val = values[i];
  cards.splice(i, 1);
  values.splice(i, 1);
  total = total + val;
}

been messing around with these for a while, testing with the console.... if I need to I can just leave the functions out, but these will help refactor my code

jshawl commented 9 years ago

what issue/bug are you running into? sorry I'm not seeing the issue

MikeDulik commented 9 years ago

i'm trying to condense the things commented above the invoked function within the function base, but I keep getting issues with variables passed to arguments being undeclared or undefined, so then I have to define/declare the variable before the function call, but then for some reason the invoked function doesn't alter the old definition of the variable, making the function pointless kinda (probably some hoisting issue I don't quite understand).... so i might just end up with 500 lines of code lol and no functions??... if I get back to that stuff today I'll re-post the issue, I seem to have broken a few other things while testing now

jshawl commented 9 years ago

ok going to close for now but please open back up if you want to discuss. Also remember to commit early and often if you need to revert changes