0

I'm trying to make a simple blackjack game on Javascript. I really don't understand why the function does not work properly?

var OurHand = 0;
var TheirHand = 0;

function dealCards() {
    OurHand += Math.floor(Math.random() * 10) + 1
    OurHand += Math.floor(Math.random() * 10) + 1
    TheirHand += Math.floor(Math.random() * 10) + 1
    TheirHand += Math.floor(Math.random() * 10) + 1
}

1 Answers1

0

You will have to execute your code using functionName() with parenthesis. Here is your example working & writing "done" in the console as an result.

var OurHand = 0;
var TheirHand = 0;

function dealCards() {
    OurHand += Math.floor(Math.random() * 10) + 1
    OurHand += Math.floor(Math.random() * 10) + 1
    TheirHand += Math.floor(Math.random() * 10) + 1
    TheirHand += Math.floor(Math.random() * 10) + 1
    console.log('Done dealing cards.')
}

dealCards() // this will execute your code of the dealCards function

console.log(OurHand)
console.log(TheirHand)
DominikAngerer
  • 6,354
  • 5
  • 33
  • 60
  • But don't I execute it in the console by typing "dealCards" ? – Petras Vilkelis Feb 09 '17 at 16:41
  • nope :) you can read more about that here: http://www.w3schools.com/js/js_function_invocation.asp or here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call – DominikAngerer Feb 09 '17 at 16:42