Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #21469

Re: Variable subtraction

From Stefan Weiss <krewecherl@gmail.com>
Newsgroups comp.lang.javascript
Subject Re: Variable subtraction
Date 2013-09-30 02:07 +0200
Organization albasani.net
Message-ID <l2afcq$mon$1@news.albasani.net> (permalink)
References <7c29d7c6-fd63-4a14-9172-86e51b0d65e3@googlegroups.com>

Show all headers | View raw


On 2013-09-30 01:34, k wrote:
> <script>
> var clicked=98;

This "clicked" is a global variable.

> function ten(){
> if(clicked<100){
> alert('Not enough clicks');
> }else{
> var clicked = - 100;
> // line above doesn't work

This "clicked" variable is local to the ten() function, because you used
"var". It has nothing to do with the global one. If you leave out the
"var", you'll address the global variable, as you probably intended.

By the way, this line would set "clicked" to -100, not subtract 100 from
it. To do substraction, you can use

  clicked = clicked - 100;

or the short form

  clicked -= 100;  // not "= -"

> function five(){
> if(clicked<200){
> alert('Not enough clicks');
> }else{
> var clicked = - 200;
> // line above doesn't work

Same reason as before.


- stefan

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Variable subtraction k <kalezwe@gmail.com> - 2013-09-29 16:34 -0700
  Re: Variable subtraction Stefan Weiss <krewecherl@gmail.com> - 2013-09-30 02:07 +0200
    Re: Variable subtraction k <kalezwe@gmail.com> - 2013-09-29 20:06 -0700

csiph-web