• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

addEventListener and buttons

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have created this script:



It doesn't work and I can't see why. This script should print out Even if you push the button when the value is even, otherwise "Uneven".

Thanks!
 
Marshal
Posts: 67418
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dani Deliani wrote:It doesn't work and I can't see why.



First thing: welcome to the Ranch!

Second: just saying "it doesn't work" isn't very helpful. In the future, please describe the issue and the steps you have taken to debug it in more detail.

Third: have you used the debugger in the browser to step through the code and see what actually happening and where it is going awry?

And finally: your code is sloppy. The if and else clauses of a conditional statement should always be enclosed in braces. Tighten up your code and you may be pleasantly surprised.
 
Dani Deliani
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:

Dani Deliani wrote:It doesn't work and I can't see why.



First thing: welcome to the Ranch!

Second: just saying "it doesn't work" isn't very helpful. In the future, please describe the issue and the steps you have taken to debug it in more detail.

Third: have you used the debugger in the browser to step through the code and see what actually happening and where it is going awry?

And finally: your code is sloppy. The if and else clauses of a conditional statement should always be enclosed in braces. Tighten up your code and you may be pleasantly surprised.



Thanks!

How do I use the debugger? I don't get any error messages.
 
Bear Bibeault
Marshal
Posts: 67418
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See the first section of the JavaScript FAQ at https://coderanch.com/t/660075/Wiki/Javascript-Links
 
Stinging nettles are edible. But I really want to see you try to eat this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic