Nested if then java statements
Copy link to clipboard
Copied
I'm working on a return/exchange item form, and I have two statements that I can't seem to figure out how to use proper syntax for (that's the error I'm getting on the very last line; I'm probably missing a close curly brace somewhere). Here is the scenario: If the return is past 90 days, the customer is responsible for paying shipping on the exchanged item; if it's within 90 days, they are not. The second "if" is that shipping is 7.95 or 11% of the total, whichever is greater. I have already defined my variables, and this is the "do it" part of my code that needs help:
if(days>90){ //var days is calculated in code above this snippet, and it works in another form field, so that's not the issue
if(amount<72.30){ //amount is a getField defined in var list
event.value = 7.95;
} else{
event.value = ship; //defined as amount*.11 in my var list
} else{
event.value = 0;
}
Copy link to clipboard
Copied
Tip: it's not "Java". It's JavaScript. This might seem to be just picky, but searching the web for info to learn Java, or looking for help with Java, will give you lots of useless advice.
What does it say in the JavaScript console?
Copy link to clipboard
Copied
Try this:
if(days>90){
if(amount<72.30)
event.value = 7.95;
else
event.value = ship;}
else
event.value = 0;
Copy link to clipboard
Copied
Excellen. That worked! I knew it was just some punctuation issues.
Copy link to clipboard
Copied
I would recommend using curly brackets for each if-condition, even if it's not needed. It would make reading the code much easier.
Copy link to clipboard
Copied
A if can't have 2 else.

