How to write this if statement?
<p>I have an application <a href="http://helios.hud.ac.uk/u0867587/testing/Testpage.php" rel="nofollow">here</a></p>

<p>When you open the application, please keep clicking on the "Add Question" button, you will realise that it would not let you add more than 5 table rows. This is because of this code here:</p>

<pre><code>    if (qnum &gt; 5) {
    return;
}
</code></pre>

<p>This line of code goes into the function below which controls adding table rows:</p>

<pre><code>var qnum = 1;

function insertQuestion(form) {   


    if (qnum &gt; 5) {
    return;
}


    var $tbody = $('#qandatbl &gt; tbody'); 
    var $tr = $("&lt;tr class='optionAndAnswer' align='center'&gt;&lt;/tr&gt;");
    var $qid = $("&lt;td class='qid'&gt;" + qnum + "&lt;/td&gt;");


    $tr.append($qid);
    $tbody.append($tr); 


    $(form).find('.numberOfQuestions').val(qnum);

    ++qnum;
    $("#questionNum").text(qnum);
    form.questionText.value = "";


}
</code></pre>

<p>The added rows go into this table here:</p>

<pre><code>&lt;table id="qandatbl" align="center"&gt;
&lt;thead&gt;
&lt;tr&gt;
    &lt;th class="qid"&gt;Question No&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;&lt;/tbody&gt;
&lt;/table&gt;
</code></pre>

<p>My question is that I am going to create a new function which is known as validation() function and this will create the alerts. What my question is that how do I write the if statement to state that if the last question number is not in a table row then display in the alert "You have not added all of your questions\n you have '' questions remaining". How do I write the if statement?</p>

<p>Below is the current validation() function at moment:</p>

<pre><code>function validation() {

    var marks = parseInt($("#total-weight").text());    
    var _qid = "";
    var _msg = "";

    var maxQuestions = &lt;?php echo (int)@$_POST['textQuestion']; ?&gt;;
    var questionsAdded = $('tr.optionAndAnswer').length;


    var alertValidation = "";
    // Note, this is just so it's declared...
    $("tr.optionAndAnswer").each(function() {


        _qid = $("td.qid",this).text();
        _msg = "You have errors on Question Number: " + _qid + "\n";

        $(".textAreaQuestion",this).each(function() {



            if (!this.value || this.value.length &lt; 5) {
                alertValidation += "\n\u2022 You have not entered a valid Question\n";
            }

            if (alertValidation != "") {
                return false; //Stop the each loop 
            }
        });

        $(".numberAnswerTxtRow",this).each(function() {


            var currenttotal = $(this).closest('.optionAndAnswer').find('.answerBtnsOn').length;

            if (!this.value) {
                alertValidation += "\n\u2022 Please Enter in the Number of Answers you Require for this question\n";
            }

            else if (currenttotal &gt; $(this).val()){
                alertValidation += "\n\u2022You have selected more answers than the required amount\n";
    }

            else if (currenttotal &lt; $(this).val()) {
                alertValidation += "\n\u2022 You have selected less answers than the required amount\n";
    }

            if (alertValidation != "") {
                return false; //Stop the each loop 
            }

        });

        $(".txtWeightRow",this).each(function() {


            if (!this.value) {
                alertValidation += "\n\u2022 Please enter in a figure for Number of Marks for this Question\n";
            }

            if (alertValidation != "") {
                return false; //Stop the each loop 
            }
        });


        if(alertValidation != ""){
            return false;
        }
    });

if(alertValidation == ""){      
            if($("#total-weight").text() &lt; '0')
{
    _msg = '';
 alertValidation = "Your Total Session Marks Remaining does not equal 0 \n\n\u2022 You Need To Remove " + Math.abs(marks) +  " Marks";   
}

        else if($("#total-weight").text() &gt; '0')
{
    _msg = '';
 alertValidation = "Your Total Session Marks Remaining does not equal 0 \n\n\u2022 You Have " + marks +  " Marks Remaining";   
}

        else if(questionsAdded  &lt; maxQuestions){
    msg = '';
     alertValidation("You Have Not Added in All of Your Questions. You have " + (maxQuestions - questionsAdded) + " Questions Remaining:" );
}


}

    if (alertValidation != "") {
        alert(_msg + alertValidation);
        return false;
    }

    return true;
}
</code></pre>
