0

【Javascript】Why do these increments and decrements NOT show on the browser?

Hi, I just recently started to study coding and I am a new learner of Javascript. Increments and decrements do not properly show on my browser, and I'd like to know why. Did I make any mistake or are these originally the numbers that cannot be shown by themselves? These did not work; var f = 5 ++; var g = 5 --; var h = ++ 5; var i = -- 5; document.write(f); document.write(g); document.write (h); document.write(i); These worked; var x = 5 - 5; var a = 5 + 5; var b = 5 * 5; var d = 5 / 5; var e = 5 % 5; document.write(a + x + b + "<BR/>"); document.write(d + "<BR/>"); document.write(e + "<BR/>"); document.write(x + "<BR/>"); document.write(a + "<BR/>"); Btw, I checked several times if there are any minor mistakes on forgetting ";" or spaces between numbers and "++" or "--". I'd appreciate it if someone can help me on this. Thank you.

22nd May 2018, 9:53 AM
Ayumi
Ayumi  - avatar
4 RĂ©ponses
+ 3
increment and decrement operators are used on variables not on numbers
22nd May 2018, 9:58 AM
‎ ‏‏‎Anonymous Guy
+ 3
try: var f = 5; f++; document.write(f);
22nd May 2018, 10:14 AM
Ulisses Cruz
Ulisses Cruz - avatar
+ 2
Sreejith Uhhh now I understand. Thank you for your help!
23rd May 2018, 7:44 AM
Ayumi
Ayumi  - avatar
0
Ulisses Cruz I tried the coding and it worked well!Thank you so much :D
23rd May 2018, 7:46 AM
Ayumi
Ayumi  - avatar