Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-07-2013, 03:25 PM   PM User | #1
Houstyn
New to the CF scene

 
Join Date: Mar 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Houstyn is an unknown quantity at this point
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
Houstyn is offline   Reply With Quote
Old 03-07-2013, 04:00 PM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
Philip M is offline   Reply With Quote
Old 03-07-2013, 06:18 PM   PM User | #3
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,452
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
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 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.8% IE9:11.4% IE10:6.5%
rnd me is offline   Reply With Quote
Old 03-07-2013, 06:21 PM   PM User | #4
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,447
Thanks: 0
Thanked 496 Times in 488 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
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/
felgall is offline   Reply With Quote
Reply

Bookmarks

Tags
game, javascripts

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:17 AM.


Advertisement
Log in to turn off these ads.