freeCodeCamp/curriculum/challenges/arabic/02-javascript-algorithms-an.../basic-javascript/comparisons-with-the-logica...

3.9 KiB

id title challengeType videoUrl localeTitle
56533eb9ac21ba0edf2244d8 Comparisons with the Logical And Operator 1 مقارنات مع المنطقية والمشغل

Description

في بعض الأحيان ستحتاج إلى اختبار أكثر من شيء واحد في كل مرة. إرجاع المنطقية والمشغل ( && ) true إذا وفقط إذا كانت المعاملات إلى اليسار واليمين صحيحاً. يمكن تحقيق نفس التأثير بتضمين جملة if داخل أخرى إذا:
if (num> 5) {
إذا (عدد <10) {
العودة "نعم" ؛
}
}
العودة "لا" ؛
سيعود فقط "نعم" إذا num أكبر من 5 وأقل من 10 . نفس المنطق يمكن كتابته على النحو التالي:
if (num> 5 & num <10) {
العودة "نعم" ؛
}
العودة "لا" ؛

Instructions

قم بدمج العبارة "if" في عبارة واحدة والتي ستُرجع "Yes" إذا كان val أقل من أو يساوي 50 وأكبر من أو يساوي 25 . خلاف ذلك ، سيعود "No" .

Tests

tests:
  - text: يجب عليك استخدام مشغل <code>&amp;&amp;</code> مرة واحدة
    testString: 'assert(code.match(/&&/g).length === 1, "You should use the <code>&&</code> operator once");'
  - text: يجب أن يكون لديك واحد فقط <code>if</code> البيان
    testString: 'assert(code.match(/if/g).length === 1, "You should only have one <code>if</code> statement");'
  - text: يجب أن ترجع <code>testLogicalAnd(0)</code> &quot;لا&quot;
    testString: 'assert(testLogicalAnd(0) === "No", "<code>testLogicalAnd(0)</code> should return "No"");'
  - text: <code>testLogicalAnd(24)</code> يجب أن ترجع &quot;لا&quot;
    testString: 'assert(testLogicalAnd(24) === "No", "<code>testLogicalAnd(24)</code> should return "No"");'
  - text: <code>testLogicalAnd(25)</code> يجب أن ترجع &quot;Yes&quot;
    testString: 'assert(testLogicalAnd(25) === "Yes", "<code>testLogicalAnd(25)</code> should return "Yes"");'
  - text: يجب أن ترجع <code>testLogicalAnd(30)</code> &quot;نعم&quot;
    testString: 'assert(testLogicalAnd(30) === "Yes", "<code>testLogicalAnd(30)</code> should return "Yes"");'
  - text: يجب أن ترجع <code>testLogicalAnd(50)</code> &quot;نعم&quot;
    testString: 'assert(testLogicalAnd(50) === "Yes", "<code>testLogicalAnd(50)</code> should return "Yes"");'
  - text: <code>testLogicalAnd(51)</code> يجب أن ترجع &quot;لا&quot;
    testString: 'assert(testLogicalAnd(51) === "No", "<code>testLogicalAnd(51)</code> should return "No"");'
  - text: يجب أن <code>testLogicalAnd(75)</code> &quot;لا&quot;
    testString: 'assert(testLogicalAnd(75) === "No", "<code>testLogicalAnd(75)</code> should return "No"");'
  - text: <code>testLogicalAnd(80)</code> يجب أن ترجع &quot;لا&quot;
    testString: 'assert(testLogicalAnd(80) === "No", "<code>testLogicalAnd(80)</code> should return "No"");'

Challenge Seed

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

// solution required