Title: Help with if statement
Last modified: February 4, 2017

---

# Help with if statement

 *  Resolved [chadtesting](https://wordpress.org/support/users/chadtesting/)
 * (@chadtesting)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/help-with-if-statement-2/)
 * Hi there,
 * I have a calculated field set up with the following code
 *     ```
       (function(){
       var prereqs = [fieldname70,fieldname312,fieldname316,fieldname320,fieldname324,fieldname308],
       prereqs;
       if fieldname70.val() != 'ENG4U' prereqs = "ENG4U needed for this program.";
       else prereqs = "Pre-requisites achieved";
       return prereqs;
       })()
       ```
   
 * The calculated field is not outputting as expected. Could someone please help?
   Thank you.

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/help-with-if-statement-2/#post-8741402)
 * Hello,
 * There are multiple errors in your code:
 * First, you don’t need call the val() for the fieldname70, because the plugin 
   replace the fields’ names by their values in the equations.
 * Second, in javascript the conditional statement “if” requires the conditions 
   be closed into parentheses.
 * Third, you are defining two times the “prereqs” variable in the same scope, generating
   a parser error.
 * Fourth, you are assigning a value to the “prereqs” variable, and are not using
   the values in the initialization, so, you don’t need assign the initial array.
 * Your equation should be edited as follows:
 *     ```
       (function(){
       if (fieldname70 != 'ENG4U') return "ENG4U needed for this program.";
       return "Pre-requisites achieved";
       })()
       ```
   
 * or even simpler, using the “IF” operation implemented by the plugin (do not confuse
   with the conditional statement “if” of javascript) :
 * `IF(fieldname70 != 'ENG4U', 'ENG4U needed for this program.', 'Pre-requisites
   achieved')`
 * Best regards.
 *  Thread Starter [chadtesting](https://wordpress.org/support/users/chadtesting/)
 * (@chadtesting)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/help-with-if-statement-2/#post-8744330)
 * I suck. Thank you, works perfectly as usual.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Help with if statement’ is closed to new replies.

 * ![](https://ps.w.org/calculated-fields-form/assets/icon-256x256.jpg?rev=1734377)
 * [Calculated Fields Form](https://wordpress.org/plugins/calculated-fields-form/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/calculated-fields-form/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/calculated-fields-form/)
 * [Active Topics](https://wordpress.org/support/plugin/calculated-fields-form/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/calculated-fields-form/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/calculated-fields-form/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [chadtesting](https://wordpress.org/support/users/chadtesting/)
 * Last activity: [9 years, 4 months ago](https://wordpress.org/support/topic/help-with-if-statement-2/#post-8744330)
 * Status: resolved