2018-10-04 14:37:37 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								id: 56533eb9ac21ba0edf2244d8
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								title: Comparisons with the Logical And Operator
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								challengeType: 1
							 
						 
					
						
							
								
									
										
										
										
											2019-02-14 12:24:02 -05:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								videoUrl: 'https://scrimba.com/c/cvbRVtr'
							 
						 
					
						
							
								
									
										
										
										
											2019-07-31 11:32:23 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								forumTopicId: 16799
							 
						 
					
						
							
								
									
										
										
										
											2018-10-04 14:37:37 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## Description
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< section  id = 'description' >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Sometimes you will need to test more than one thing at a time. The < dfn > logical and< / dfn >  operator (< code > & & < / code > ) returns < code > true< / code >  if and only if the < dfn > operands< / dfn >  to the left and right of it are true.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								The same effect could be achieved by nesting an if statement inside another if:
							 
						 
					
						
							
								
									
										
										
										
											2019-05-17 06:20:30 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								if (num > 5) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  if (num <  10 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return "Yes";
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								return "No";
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-10-04 14:37:37 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								will only return "Yes" if < code > num< / code >  is greater than < code > 5< / code >  and less than < code > 10< / code > . The same logic can be written as:
							 
						 
					
						
							
								
									
										
										
										
											2019-05-17 06:20:30 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								if (num > 5 & &  num <  10 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  return "Yes";
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								return "No";
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2018-10-04 14:37:37 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								< / section >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## Instructions
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< section  id = 'instructions' >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Combine the two if statements into one statement which will return < code > "Yes"< / code >  if < code > val< / code >  is less than or equal to < code > 50< / code >  and greater than or equal to < code > 25< / code > . Otherwise, will return < code > "No"< / code > .
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / section >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## Tests
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< section  id = 'tests' >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```yml
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								tests:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  -  text: You should use the < code > && </ code >  operator once
							 
						 
					
						
							
								
									
										
										
										
											2019-07-13 00:07:53 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    testString: assert(code.match(/& & /g).length === 1);
							 
						 
					
						
							
								
									
										
										
										
											2018-10-04 14:37:37 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  -  text: You should only have one < code > if</ code >  statement
							 
						 
					
						
							
								
									
										
										
										
											2019-07-13 00:07:53 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    testString: assert(code.match(/if/g).length === 1);
							 
						 
					
						
							
								
									
										
										
										
											2018-10-04 14:37:37 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  -  text: < code > testLogicalAnd(0)</ code >  should return "No"
							 
						 
					
						
							
								
									
										
										
										
											2019-07-13 00:07:53 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    testString: assert(testLogicalAnd(0) === "No");
							 
						 
					
						
							
								
									
										
										
										
											2018-10-04 14:37:37 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  -  text: < code > testLogicalAnd(24)</ code >  should return "No"
							 
						 
					
						
							
								
									
										
										
										
											2019-07-13 00:07:53 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    testString: assert(testLogicalAnd(24) === "No");
							 
						 
					
						
							
								
									
										
										
										
											2018-10-04 14:37:37 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  -  text: < code > testLogicalAnd(25)</ code >  should return "Yes"
							 
						 
					
						
							
								
									
										
										
										
											2019-07-13 00:07:53 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    testString: assert(testLogicalAnd(25) === "Yes");
							 
						 
					
						
							
								
									
										
										
										
											2018-10-04 14:37:37 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  -  text: < code > testLogicalAnd(30)</ code >  should return "Yes"
							 
						 
					
						
							
								
									
										
										
										
											2019-07-13 00:07:53 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    testString: assert(testLogicalAnd(30) === "Yes");
							 
						 
					
						
							
								
									
										
										
										
											2018-10-04 14:37:37 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  -  text: < code > testLogicalAnd(50)</ code >  should return "Yes"
							 
						 
					
						
							
								
									
										
										
										
											2019-07-13 00:07:53 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    testString: assert(testLogicalAnd(50) === "Yes");
							 
						 
					
						
							
								
									
										
										
										
											2018-10-04 14:37:37 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  -  text: < code > testLogicalAnd(51)</ code >  should return "No"
							 
						 
					
						
							
								
									
										
										
										
											2019-07-13 00:07:53 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    testString: assert(testLogicalAnd(51) === "No");
							 
						 
					
						
							
								
									
										
										
										
											2018-10-04 14:37:37 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  -  text: < code > testLogicalAnd(75)</ code >  should return "No"
							 
						 
					
						
							
								
									
										
										
										
											2019-07-13 00:07:53 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    testString: assert(testLogicalAnd(75) === "No");
							 
						 
					
						
							
								
									
										
										
										
											2018-10-04 14:37:37 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  -  text: < code > testLogicalAnd(80)</ code >  should return "No"
							 
						 
					
						
							
								
									
										
										
										
											2019-07-13 00:07:53 -07:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    testString: assert(testLogicalAnd(80) === "No");
							 
						 
					
						
							
								
									
										
										
										
											2018-10-04 14:37:37 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / section >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## Challenge Seed
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< section  id = 'challengeSeed' >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< div  id = 'js-seed' >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								function testLogicalAnd(val) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  // Only change code below this line
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  if (val) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if (val) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      return "Yes";
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  // Only change code above this line
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  return "No";
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// Change this value to test
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								testLogicalAnd(10);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / div >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / section >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## Solution
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< section  id = 'solution' >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								function testLogicalAnd(val) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  if (val >= 25 & &  val < = 50) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return "Yes";
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  return "No";
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / section >