vendredi 18 novembre 2016

How do I code a simple dice gambling game?

enter image description hereHere is my current code:

  • Html

    Dice - Roll above 50 to win

  • Javascript

    var randomNum = Math.floor((Math.random() * 100) + 1); var pass = 50;

    if ( randomNum > pass ) { msg = 'You won! '; } else { msg = ' You lost! ' }

    var el = document.getElementById('info'); el.textContent = msg + 'You rolled: ' + randomNum;

Scenario:

  1. Person clicks button for free credits
  2. Button adds 5 Credits to his balance
  3. He clicks a button to run the dice
  4. If he wins +10 to his balance, if he loses -5 to his balance

How would someone code that? ( I am a beginner in js ) Thanks!




Aucun commentaire:

Enregistrer un commentaire