• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

JavaScript slot game

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to make a slot game using javascript. I need some help here because i'm stuck. I used an Array to store the images. I calculate an random number so it takes an image from the array an place it into the src in the HTML file. Then it looks if the images are the same and calculate the ouput in €. If the user clicks on the spin button it had to do the functions.

The eventListener does't do anything when i click it? Does anybody know why they don't listen to the clicks?



Slot Machine


 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch!

How have you verified that the event listeners are not getting called? Setting breakpoints on the appropriate lines of code?

Have you verified that your element references are correct in the first place? (Hint: they're not.)

And why aren't you using jQuery to make this all much much simpler?
 
jor kol
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can only use js for this assignement
 
Bear Bibeault
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You answered only the last of my 4 questions.

Set a breakpoint in the code and inspect your variables. Which one is wrong?
 
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you haven't you should have a quick look over the Javascript Links (Wiki forum at Coderanch)
Right now you should be interested in the "Debugging" section.

For example if you are allowed to use Google Chrome/Chromium as your browser you should be looking at:
Chrome DevTools Overview - Google Chrome: Debugging JavaScript
and
Debugging JavaScript - Google Chrome: Debugging with breakpoints
so that you can follow Bear's advice:

Bear Bibeault wrote:Set a breakpoint in the code [, step through your code] and inspect your variables. Which one is wrong?[For example, is any variable null or undefined when you don't expect it to be - is there an error message in the JavaScript console that may indicate that something has gone wrong?]

 
Switching from electric heat to a rocket mass heater reduces your carbon footprint as much as parking 7 cars. Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic