Jump to content

increment and decrement help?


XHTMLboy

Recommended Posts

Hi, i am new to javascript and am finding something which i can't do which is how to increment and decrement properly. I have been trying to do it mostly all day but does not work. Help is much appreciated. And if you have a comment to make, can you please try to explane it so it's not to hard to understand.thanks :)so do they work like this?var string1 = 20;var string2 = string1++;alert(string2);alert(string1);i think i am right but not sure. And is that all their is?

Link to comment
Share on other sites

Is that your code exactly? Although you are calling it a string, as long as you don't have quotes around it then yes, that should work. Did you try it? What are you getting instead?

Link to comment
Share on other sites

Is that your code exactly? Although you are calling it a string, as long as you don't have quotes around it then yes, that should work. Did you try it? What are you getting instead?
Basicly if i load my first comment's piece of code into the browser with the alert changed back to alert(string1); being up the top, you get 21 followed by 20. I just wanted to know why it did the 21 first, and what all the different type of increments and decrements are as the book i have a home explanes it in a really hard to understand way. And thankyou for your help
Link to comment
Share on other sites

think you looking forvar string1 = 20;string1++;var string2 = string1;alert(string1);alert(string2);orvar string1 = 20;var string2 = ++string1;alert(string1);alert(string2);
I think the top one would have been a better way of doing it, because with my one i had the change the alerts the other way around. :) Thankyou for your time and help :)
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...