Hello and welcome to our community! Is this your first visit?
Register
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
    Posts
    1
    Thanks
    0
    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,

    Houstyn

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,918
    Thanks
    203
    Thanked 2,531 Times in 2,509 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:-

    Code:
    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
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,296
    Thanks
    10
    Thanked 584 Times in 565 Posts
    in 64 seconds:
    Code:
    alert(
    [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!"
    )
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,623
    Thanks
    0
    Thanked 645 Times in 635 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.
    Stephen
    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
    •