D
D
danilstep2018-02-17 14:04:10
JavaScript
danilstep, 2018-02-17 14:04:10

The most stupid and easy question is how to add a value to a variable?

There is one problem, I created a variable and I can’t change its value to +2 in any way, that is:
var a = 0
a = +2
alert(a)
And the alert should output 2.


var ans;
varsum;
alert("Hello, this psychological test is for those who are not sure if they will ever win. The test consists of seventeen (17) questions."," ");
alert("OK = yes; Cancel = No"," ");
ans = confirm("1. I always know what I'll do if I fail, but I never talk about it. "," ");
if (ans==true){
sum += 2
alert(sum)
alert(ans)
}
ml>

And as a result sum = NaN

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Ler Den, 2018-02-17
@danilstep

redeclared the variable. Try without a new var declaration i.e.
var a = 0
a +=2
alert(a)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question