• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How do you use conditional statements more effectively?

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I type in



, the things that I have inputted do not function correctly on an IE page. Then I place this link at the end (location.href="addurlhere"), and instead of allowing to do what is above, it jumps straight to the link, trying to take me to the site in question. How does one accurately execute a conditional statement in such a way that I'm trying to convey.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch, Nathan!

I added code tags to your post so it's more readable (in future, look for the "Code" button at the top of the posting box).

Also, since Java isn't the same as Javascript, and your code is Javascript, I moved your post to the forum where Javascript questions are answered.
 
Sheriff
Posts: 67746
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
To be honest, I'm not sure what you are trying to do. Firstly, using alerts to debug is a poor approach. It interrupts the execution flow and so does not give you an accurate representation of how the code is running. Avoid them.

Rather, learn how to use the tools in the browser. Open the JavaScript console (how, depends upon your browser), and use console.log() for tracing in place of alerts.

Also, please post complete code examples (the link you mention doesn't appear in your code so it's a mystery), be sure to UseCodeTags, and be sucre that your code is properly indented and formatted.
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does your code really have "name" in one place and "name1" in another? That's unlikely to be doing what you intended.
 
Greenhorn
Posts: 25
Eclipse IDE Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you comparing a "name" variable with a "num" variable. It doesn't make sense semantically. Try using more meaningful identifier names. It looks like you're trying to check an "age", which would be a more meaningful identifier. Also, why do you have a conditional expression on your "else" statement. I don't think that should work.
 
Bear Bibeault
Sheriff
Posts: 67746
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

Brian Schuetz wrote:Also, why do you have a conditional expression on your "else" statement. I don't think that should work.


Yeah, there's certainly a syntax issue there.

An else-if is a valid construct, however, I'd argue that a switch is almost always preferable to an else-if construct.

And yes, good names are mandatory. Not negotiable. Not optional. Mandatory.

Still waiting for the OP to clarify intentions and post complete code.

I'll ignore the blatant age-ism for now.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic