1

I'm new to Javascript.

I have a script with lots of calculations. Everything is working great except I have a variable called J14 and the user is able to set this value from the interface. Lets say it equals 30000 for now. It seems to work through the calculations but as soon as I use J14 in an If statement condition, it replaces the value of J14 with 0. I have no idea why it would do this as I'm not assigning the variable, I'm simply checking it against 0.

Before this statement I can output the value of J14 and it's 30000 as expected, however, if I output J14 after this statement it's value is 0. So the condition is assigning the value. I can then no longer use J14 in the script but I need to use it in the If statement following this one. I probably have syntax error for doing this kind of thing but can't quite figure out the terminology for a successful google for a solution.

if (J14 = 0)
{
    J59 = (J15 + J16) * 75;
}
else
{
    J59 = J15 * F75;

}

3 Answers 3

4

= is an assignment. You should use == or better yet, ===.

Sign up to request clarification or add additional context in comments.

1 Comment

You know I nearly did that but didn't find it as an option on the site I used as a tutorial, it only had others such as != <= etc etc but no ==. I should have known from other programming languages I've used.
2

You are assigning 0 to the variable. = is used for assignment. You need to use '=='.

Comments

1

= is an Assignment Operator.

== is Comparison Operator

if (J14 = 0)   //will assign 0 to J14

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.