HTML Diff
0 added 0 removed
Original 2026-01-01
Modified 2026-03-09
1 <p>We told JavaScript to change the color of the bar to red if the password is too short. If the password is of average length, then the bar should turn yellow.</p>
1 <p>We told JavaScript to change the color of the bar to red if the password is too short. If the password is of average length, then the bar should turn yellow.</p>
2 <p>What do we mean by “average length”? This means that the password is greater than 5 characters<b>AND</b>less than 10 characters long. To create a double condition, use the<a>logical operator AND</a>:</p>
2 <p>What do we mean by “average length”? This means that the password is greater than 5 characters<b>AND</b>less than 10 characters long. To create a double condition, use the<a>logical operator AND</a>:</p>
3 passLength &gt; 5 &amp;&amp; passLength &lt; 10<p>But where do we indicate this condition? Use the else if statement. It allows you to add an alternative branch with the following condition to the conditional statement:</p>
3 passLength &gt; 5 &amp;&amp; passLength &lt; 10<p>But where do we indicate this condition? Use the else if statement. It allows you to add an alternative branch with the following condition to the conditional statement:</p>
4 if (passLength &lt;= 5) { // The instructions are executed if the first condition is true } else if (passLength &gt; 5 &amp;&amp; passLength &lt; 10) { // The instructions are executed if the second condition is true }<p>Indicate the condition in parentheses after else if, and indicate the instructions that should be executed in curly braces if the condition returns true.</p>
4 if (passLength &lt;= 5) { // The instructions are executed if the first condition is true } else if (passLength &gt; 5 &amp;&amp; passLength &lt; 10) { // The instructions are executed if the second condition is true }<p>Indicate the condition in parentheses after else if, and indicate the instructions that should be executed in curly braces if the condition returns true.</p>
5 <p>Imagine that a user entered a password that was 6 characters long. JavaScript first checks the first condition: is the password length less than or equal to 5 characters? No. So, let’s move on. Check the next condition: is the password longer than 5 characters, but less than 10? Yes. This means that we will execute the instructions from the second branch.</p>
5 <p>Imagine that a user entered a password that was 6 characters long. JavaScript first checks the first condition: is the password length less than or equal to 5 characters? No. So, let’s move on. Check the next condition: is the password longer than 5 characters, but less than 10? Yes. This means that we will execute the instructions from the second branch.</p>
6 <p>You can have as many else if branches in the conditional statement as you want. But the more you have of them, the more confusing the code is.</p>
6 <p>You can have as many else if branches in the conditional statement as you want. But the more you have of them, the more confusing the code is.</p>
7 <p>Add an else if branch to the conditional statement, and tell JavaScript to change the color of the bar to yellow if the password is longer than 5 characters but shorter than 10.</p>
7 <p>Add an else if branch to the conditional statement, and tell JavaScript to change the color of the bar to yellow if the password is longer than 5 characters but shorter than 10.</p>
8 <p><i>Instead of yellow, we’ll actually use the colour gold, because that will show up better against the page’s background colour.</i></p>
8 <p><i>Instead of yellow, we’ll actually use the colour gold, because that will show up better against the page’s background colour.</i></p>