--- id: 56533eb9ac21ba0edf2244d8 title: Comparisons with the Logical And Operator challengeType: 1 videoUrl: '' localeTitle: Comparaciones con lo lógico y el operador. --- ## Description
A veces necesitará probar más de una cosa a la vez. La lógica y el operador ( && ) devuelven true si y solo si los operandos a su izquierda y derecha son verdaderos. El mismo efecto podría lograrse anidando una instrucción if dentro de otra si:
if (num> 5) {
si (num <10) {
devuelve "Sí";
}
}
devuelve "No";
solo devolverá "Sí" si num es mayor que 5 y menor que 10 . La misma lógica se puede escribir como:
if (num> 5 && num <10) {
devuelve "Sí";
}
devuelve "No";
## Instructions
Combine las dos declaraciones if en una declaración que devolverá "Yes" si val es menor o igual a 50 y mayor o igual a 25 . De lo contrario, devolverá "No" .
## Tests
```yml tests: - text: Debe usar el operador && una vez testString: 'assert(code.match(/&&/g).length === 1, "You should use the && operator once");' - text: Sólo debe tener una declaración if testString: 'assert(code.match(/if/g).length === 1, "You should only have one if statement");' - text: testLogicalAnd(0) debe devolver "No" testString: 'assert(testLogicalAnd(0) === "No", "testLogicalAnd(0) should return "No"");' - text: testLogicalAnd(24) debe devolver "No" testString: 'assert(testLogicalAnd(24) === "No", "testLogicalAnd(24) should return "No"");' - text: testLogicalAnd(25) debe devolver "Sí" testString: 'assert(testLogicalAnd(25) === "Yes", "testLogicalAnd(25) should return "Yes"");' - text: testLogicalAnd(30) debe devolver "Sí" testString: 'assert(testLogicalAnd(30) === "Yes", "testLogicalAnd(30) should return "Yes"");' - text: testLogicalAnd(50) debe devolver "Sí" testString: 'assert(testLogicalAnd(50) === "Yes", "testLogicalAnd(50) should return "Yes"");' - text: testLogicalAnd(51) debe devolver "No" testString: 'assert(testLogicalAnd(51) === "No", "testLogicalAnd(51) should return "No"");' - text: testLogicalAnd(75) debe devolver "No" testString: 'assert(testLogicalAnd(75) === "No", "testLogicalAnd(75) should return "No"");' - text: testLogicalAnd(80) debe devolver "No" testString: 'assert(testLogicalAnd(80) === "No", "testLogicalAnd(80) should return "No"");' ```
## Challenge 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); ```
## Solution
```js // solution required ```