Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Mar 2013
    Thanked 0 Times in 0 Posts

    Simple Javascripts game

    Hey everyone,

    I have to make a simple Javascript game for a school assignment. I tried a lot of stuff already, but I can't get it to work.

    My idea is a russian roulette game, where your able to chose the amount of bullets you want to put in the revolver. The higher the amount, how more chance you have to lose offcourse. It is kind of the idea of this version I found: http://www.javascriptkit.com/script/...roulette.shtml
    The only problem is, that I'm not allowed to use it in html. I have to use console.log instead of the picture. A seperated window to be more precise.

    Anyone that can help me making this game? I don't think it's very hard but I just started Javascripts and I don't understand anything of it. Especially making the computer chose a random number between 1-6 to decide whether you are dead or not.

    Thank you in advance,


  2. #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    London, England
    Thanked 2,699 Times in 2,675 Posts
    Please have look at forum rule #1.5.

    This forum is not a free coding service. As a general rule, the people helping out in this forum don't write code for others (especially code that appears to be for homework), but try to help with fixing code that doesn't work. You may perhaps get someone to write this script for you, but you'll be far more likely to get help if you have made a substantial effort and written some code yourself. Then someone here will almost certainly help you correct/improve your work.

    As a boon I will show you how to generate a random number from 1-6:-

    var randy = Math.floor(Math.random() * 6 +1);  // generates 1-6 randomly
    alert (randy); // to inspect the result
    Quizmaster: The Garden of Gethsemane in Jerusalem is at the foot of the Mount of ... what?
    Contestant: Everest.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  3. #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Thanked 626 Times in 605 Posts
    in 64 seconds:
    [0,1,2,3,4,5].map(function(a){return a<this},prompt("how many bullets",1))
    [  Math.floor(Math.random() * 6 +1) ] ?
     "Bang, you're dead":
     "Whew, you should stop while you're ahead!"
    Create, Share, and Debug HTML pages and snippets with a cool new web app I helped create: pagedemos.com

  4. #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Sydney, Australia
    Thanked 932 Times in 919 Posts
    Of course you should never use either prompt or alert in a script intended for use in the 21st century. Most browsers now assume that those will only be used for debugging. If I were to run rnd_me's script then I could set the checkbox in the prompt instead of typing in a number and bang JavaScript's dead for this page and none of the rest of the script gets to run.
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts