Flash Website Builder- Trendy Site Builder is a Flash Site Building tool that helps users build stunning websites. Check Out Custom Custom Logo Design by LogoBee. Website Design and Free Logo Templates available.

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 03-14-2013, 11:39 PM PM User | #1 jessiemaewho New to the CF scene   Join Date: Mar 2013 Posts: 2 Thanks: 1 Thanked 0 Times in 0 Posts 3 digit guessing game, please help debug I'm not sure where I went wrong, looking for some direction as to why this won't run for me. I have a .html and an external .js HTML: Code: ``` Lottery Game

Welcome to the lottery game!

Here's how it works:

Guess three numbers from 0 to 9.
Any one matching number wins \$10.
Two matching numbers wins \$1000.
Three matching numbers, in exact order, wins \$1,000,000.
No matches wins nothing.

Your guess for the first number:
Your guess for the second number:
Your guess for the third number:

``` JS: Code: ``` ``` The html seems to work just fine, but the function lotto() does not run when the button is clicked, and I'm not sure why. Any help in directing me where I went wrong would be much appreciated! Thanks in advance. Last edited by VIPStephan; 03-15-2013 at 11:34 PM.. Reason: fixed code BB tags
 03-15-2013, 05:24 PM PM User | #2 sunfighter Senior Coder   Join Date: Jan 2011 Location: Missouri Posts: 3,289 Thanks: 23 Thanked 473 Times in 472 Posts Use the hash mark # located above you in the tool bar to generate the [code] tags. I did change your code a bit. Your problem was in the else if's Code: ``` Lottery Game

Welcome to the lottery game!

Here's how it works:

Guess three numbers from 0 to 9.
Any one matching number wins \$10.
Two matching numbers wins \$1000.
Three matching numbers, in exact order, wins \$1,000,000.
No matches wins nothing.

Your guess for the first number:
Your guess for the second number:
Your guess for the third number:

``` Last edited by sunfighter; 03-15-2013 at 05:30 PM..
 Users who have thanked sunfighter for this post: jessiemaewho (03-15-2013)
 03-15-2013, 05:27 PM PM User | #3 WolfShade Regular Coder   Join Date: Apr 2012 Location: St. Louis, MO, USA Posts: 966 Thanks: 7 Thanked 100 Times in 100 Posts Your external jQuery file should load before the external lotto.js file, I think. And they should both load just before the closing tag. __________________ ^_^ If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link. * The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest". Last edited by WolfShade; 03-15-2013 at 05:30 PM..
 03-15-2013, 05:29 PM PM User | #4 jmrker Senior Coder     Join Date: Aug 2006 Location: FL Posts: 2,935 Thanks: 36 Thanked 477 Times in 471 Posts I don't use JQuery, so that part you'll need to work out yourself. However, concerning the 'document.write()' statements: You cannot execute those statements AFTER the page has initially displayed. Doing so will cause the display to change to the INITIAL conditions of the display and you will lose all input you have made during your guessing process. Consider writing to a
section using 'getElementById('elementNameToWriteTo').innerHTML = '????'
 03-15-2013, 09:47 PM PM User | #5 jessiemaewho New to the CF scene   Join Date: Mar 2013 Posts: 2 Thanks: 1 Thanked 0 Times in 0 Posts Thank you Sunfighter! I changed it a bit, so guess2 can match lottonum[0] etc... Code: ``` Lottery Game

Welcome to the lottery game!

Here's how it works:

Guess three numbers from 0 to 9.
Any one matching number wins \$10.
Two matching numbers wins \$1000.
Three matching numbers, in exact order, wins \$1,000,000.
No matches wins nothing.

Your guess for the first number:
Your guess for the second number:
Your guess for the third number:

```
 03-16-2013, 03:41 AM PM User | #6 jmrker Senior Coder     Join Date: Aug 2006 Location: FL Posts: 2,935 Thanks: 36 Thanked 477 Times in 471 Posts Alternative solution ... just for fun! Compressed the code a little, especially in the logic tests. I also added check to assure the user only enters valid numbers 0...9 I did not see the need to use a sledge-hammer (JQuery) on a tack. I also modified your game to add a bit of gambling by causing each lotto number to cost you \$5 Finally, I made it so that you did not have to re-start the game for each bet. Just click on the button for another random number. Code: ``` Lottery Game

Welcome to the lottery game!

Here's how it works:

Guess three numbers from 0 to 9.
Any one matching number wins \$10.
Two matching numbers wins \$50.
Three matching numbers, in any order, wins \$1,000.
Three matching numbers, in exact order, wins \$10,000.
No matches wins nothing, but will cost you \$5 to play.

```

 Bookmarks

 Tags game, guessing, javascript, lottery

 Thread Tools Rate This Thread Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 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 Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home :: Client side development     JavaScript programming         DOM and JSON scripting         Ajax and Design         JavaScript frameworks         Post a JavaScript     HTML & CSS     XML     Flash & ActionScript         Adobe Flex     Graphics and Multimedia discussions     General web building         Site reviews         Building for mobile devices :: Server side development     Apache configuration     Perl/ CGI     PHP         Post a PHP snippet     MySQL         Other Databases     Ruby & Ruby On Rails     ASP     ASP.NET     Java and JSP     Other server side languages/ issues         ColdFusion         Python :: Computing & Sciences     Computer Programming     Computer/PC discussions     Geek News and Humour Web Projects and Services Marketplace     Web Projects         Small projects (quick fixes and changes)         Medium projects (new script, new features, etc)         Large Projects (new web application, complex features etc)         Unknown sized projects (request quote)         Vacant job positions         Looking for work/ for hire         Project collaboration/ partnership         Paid work offers and requests (Now CLOSED)     Career, job, and business ideas or advice     Domains, Sites, and Designs for sale         Domains for sale         Websites for sale         Design templates and graphics for sale :: Other forums     Member Offers     Forum feedback and announcements

All times are GMT +1. The time now is 06:04 PM.