HTML Diff
0 added 0 removed
Original 2026-01-01
Modified 2026-03-09
1 <p>Excellent. Now the character counter shows the length of the new comment! If the comment is longer than 142 characters, we need to show an error message: the character counter and the text in the input field should turn red. For the message to appear, you need to add the warning class to the comment form. We have already worked with this form in the<a>previous chapter</a>. It is saved in the commentForm variable.</p>
1 <p>Excellent. Now the character counter shows the length of the new comment! If the comment is longer than 142 characters, we need to show an error message: the character counter and the text in the input field should turn red. For the message to appear, you need to add the warning class to the comment form. We have already worked with this form in the<a>previous chapter</a>. It is saved in the commentForm variable.</p>
2 <p>The error message should appear only if the new comment is too long. The use of the word “if” in an assignment is a sure sign that we need a conditional statement. We already learned about the if statement in <a>this assignment</a>.</p>
2 <p>The error message should appear only if the new comment is too long. The use of the word “if” in an assignment is a sure sign that we need a conditional statement. We already learned about the if statement in <a>this assignment</a>.</p>
3 <p>To determine if the character limit is exceeded, compare the comment length with the number 142. To do this, use the comparison operator &gt; (“greater than”). It compares two numbers and returns a Boolean value: true if the the left one is greater than the right one and false in all other cases. For example:</p>
3 <p>To determine if the character limit is exceeded, compare the comment length with the number 142. To do this, use the comparison operator &gt; (“greater than”). It compares two numbers and returns a Boolean value: true if the the left one is greater than the right one and false in all other cases. For example:</p>
4 console.log(3 &gt; 2); // Returns: true console.log(1 &gt; 2); // Returns: false console.log(2 &gt; 2); // Returns: false<p>To check whether the new comment falls within the prescribed length, we add a conditional statement to our script: compare the length of the text from the input field with the number 142 and, if the length is longer, add the warning class to the form. Then test how well the verification works by trying to submit a comment that is too long.</p>
4 console.log(3 &gt; 2); // Returns: true console.log(1 &gt; 2); // Returns: false console.log(2 &gt; 2); // Returns: false<p>To check whether the new comment falls within the prescribed length, we add a conditional statement to our script: compare the length of the text from the input field with the number 142 and, if the length is longer, add the warning class to the form. Then test how well the verification works by trying to submit a comment that is too long.</p>