Files
freeCodeCamp/curriculum/challenges/arabic/02-javascript-algorithms-and-data-structures/basic-javascript/use-conditional-logic-with-if-statements.md
2022-10-20 09:13:17 -07:00

3.1 KiB

id, title, challengeType, videoUrl, forumTopicId, dashedName
id title challengeType videoUrl forumTopicId dashedName
cf1111c1c12feddfaeb3bdef استخدام المنطق الشرطي مع تعبيرات If 1 https://scrimba.com/c/cy87mf3 18348 use-conditional-logic-with-if-statements

--description--

تستخدم تعبيرات if لإخذ القرارات في الكود البرمجي. تخبر كلمة if لغة JavaScript بتنفيذ التعليمات البرمجية داخل الأقواس المتعرجة (curly braces) تحت شروط معينة, تكون معرفة في الأقواس (parentheses). تعرف هذه الشروط بالشروط المنطقية Boolean ويمكن أن تكون فقط صحيحة true أو خاطئة false.

عندما يتم تقييم الشرط إلى صحيح true، يقوم البرنامج بتنفيذ التعبيرات البرمجية داخل الأقواس المتعرجة (curly braces). عندما يتم تقييم الشرط إلى خطأ false، التعليمات البرمجية داخل الأقواس المتعرجة (curly braces) لن تنفذ.

كود زائف (Pseudocode)

عندما (تكون حالة الشرط true) {
  يتم تنفيذ التعبير
}

مثال

function test (myCondition) {
  if (myCondition) {
    return "It was true";
  }
  return "It was false";
}

test(true);
test(false);

ينتج test(true) مقطع It was true، وينتج test(false) مقطع It was false.

عندما يتم استدعاء test بقيمة true، ويكون تعبير if يقيّم myCondition لتتيقن من أنها true أو لا. نظرًا لأنه true، فإن الوظيفة تنتج It was true. عندما تتصل ب test بقيمة false، يكون myCondition بقيمة غير true ولم يتم تنفيذ العبارة الواردة في الأقواس المنحنية وتنتج الوظيفة It was false.

--instructions--

أنشئ تعبير if داخل الوظيفة لينتج Yes, that was true إذا حالة الحجة wasThatTrue تكون true وتنتج No, that was false خلافا لذلك.

--hints--

يجب أن تكون trueOrFalse وظيفة

assert(typeof trueOrFalse === 'function');

يجب أن تنتج trueOrFalse(true) مقطع نصي

assert(typeof trueOrFalse(true) === 'string');

يجب أن تنتج trueOrFalse(false) مقطع نصي

assert(typeof trueOrFalse(false) === 'string');

يجب أن تنتج trueOrFalse(true) مقطع نصي Yes, that was true

assert(trueOrFalse(true) === 'Yes, that was true');

يجب أن تنتج trueOrFalse(false) مقطع نصي No, that was false

assert(trueOrFalse(false) === 'No, that was false');

--seed--

--seed-contents--

function trueOrFalse(wasThatTrue) {
  // Only change code below this line



  // Only change code above this line

}

--solutions--

function trueOrFalse(wasThatTrue) {
  if (wasThatTrue) {
    return "Yes, that was true";
  }
  return "No, that was false";
}