Dice roll

Kindergarten question!

Page 1 of 1

11 Replies - 9580 Views - Last Post: 05 December 2009 - 10:00 PM

#1 sirva  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 16-July 05

Dice roll

Posted 16 July 2005 - 02:42 PM

Can some patient soul help a very new newbie?

This code runs netscape and gives the result of a single dice roll - or should do. How do I make the 'document.write' line in the 'playgame function show the result of each throw?

Some of you may recognise this question, it's from an exam (I failed!), its bugging me that I can't figure it out.

Thanks.
Is This A Good Question/Topic? 0
  • +

Replies To: Dice roll

#2 skyhawk133  Icon User is offline

  • Head DIC Head
  • member icon

Reputation: 1875
  • View blog
  • Posts: 20,284
  • Joined: 17-March 01

Re: Dice roll

Posted 16 July 2005 - 03:19 PM

Can you paste the code so we can take a look, or are you asking for the solution?
Was This Post Helpful? 0
  • +
  • -

#3 sirva  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 16-July 05

Re: Dice roll

Posted 16 July 2005 - 04:22 PM

oops! - said I'm a newbie!!

<html>
<head>

<script
language="Javascript"
type="text/javascript">


function rollDie () {

var result = 0;

result = Math.floor((Math.random() * 6) + 1);

return result;
}


function playGame () {

document.open ();
document.write ('HELP NEEDED WITH THIS BIT.');
document.close ();
}
</script>
</head>


<body>
<form
action=""
method="get"
name="dieForm">

<input
name="rollButton"
type="button"
value="Roll the Die"
onclick = "playGame();">
</form>
</body>
</html>
Was This Post Helpful? 0
  • +
  • -

#4 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Dice roll

Posted 18 July 2005 - 05:41 PM

Try this:
onclick = "document.write(Math.floor(Math.random() * 6) + 1);"


Was This Post Helpful? 0
  • +
  • -

#5 sirva  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 16-July 05

Re: Dice roll

Posted 22 July 2005 - 10:19 PM

Thanks much!!
Was This Post Helpful? 0
  • +
  • -

#6 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Dice roll

Posted 23 July 2005 - 05:34 AM

No problem...have a great day!
Was This Post Helpful? 0
  • +
  • -

#7 dumanddumer  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 04-December 09

Re: Dice roll

Posted 04 December 2009 - 09:32 PM

could anyone post a code for 4 dice with button to roll them?
Was This Post Helpful? 0
  • +
  • -

#8 Lemur  Icon User is offline

  • Pragmatism over Dogma
  • member icon


Reputation: 1368
  • View blog
  • Posts: 3,455
  • Joined: 28-November 09

Re: Dice roll

Posted 05 December 2009 - 06:52 PM

http://lmgtfy.com/?q...rolling+program
Was This Post Helpful? 0
  • +
  • -

#9 dumanddumer  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 04-December 09

Re: Dice roll

Posted 05 December 2009 - 08:33 PM

~amateur code removed~

So could you at least tell me why my work here doesn't tally up results when I hit the show results button?

This post has been edited by dumanddumer: 06 December 2009 - 06:06 AM

Was This Post Helpful? 0
  • +
  • -

#10 Lemur  Icon User is offline

  • Pragmatism over Dogma
  • member icon


Reputation: 1368
  • View blog
  • Posts: 3,455
  • Joined: 28-November 09

Re: Dice roll

Posted 05 December 2009 - 09:23 PM

Because all you have are a lot of declared variables, some math, and no display methods such as alert or otherwise. It helps if you understand code before you copy and paste it, read up on java script:
http://www.w3schools.com
Was This Post Helpful? 0
  • +
  • -

#11 dumanddumer  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 04-December 09

Re: Dice roll

Posted 05 December 2009 - 09:53 PM

thanx lemur
Was This Post Helpful? 0
  • +
  • -

#12 Lemur  Icon User is offline

  • Pragmatism over Dogma
  • member icon


Reputation: 1368
  • View blog
  • Posts: 3,455
  • Joined: 28-November 09

Re: Dice roll

Posted 05 December 2009 - 10:00 PM

No problem
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1