freeCodeCamp/curriculum/challenges/arabic/02-javascript-algorithms-an.../basic-javascript/adding-a-default-option-in-...

3.7 KiB

id title challengeType guideUrl videoUrl localeTitle
56533eb9ac21ba0edf2244de Adding a Default Option in Switch Statements 1 https://arabic.freecodecamp.org/guide/certificates/adding-a-default-option-in-switch-statements إضافة خيار افتراضي في تبديل البيانات

Description

في بيان switch قد لا تتمكن من تحديد جميع القيم المحتملة كبيانات case . بدلاً من ذلك ، يمكنك إضافة العبارة default التي سيتم تنفيذها في حالة عدم العثور على عبارات case مطابقة. أعتقد أنه من مثل النهائي else بيان في if/else السلسلة. يجب أن تكون العبارة default هي الحالة الأخيرة.
التبديل (عدد) {
قيمة الحالة 1:
statement1.
استراحة؛
قيمة الحالة 2:
statement2.
استراحة؛
...
الافتراضي:
defaultStatement.
استراحة؛
}

Instructions

اكتب عبارة تبديل لتعيين answer عن الشروط التالية:
"a" - "apple"
"b" - "طائر"
"c" - "cat"
default - "الاشياء"

Tests

tests:
  - text: يجب أن يكون لـ <code>switchOfStuff(&quot;a&quot;)</code> قيمة &quot;apple&quot;
    testString: 'assert(switchOfStuff("a") === "apple", "<code>switchOfStuff("a")</code> should have a value of "apple"");'
  - text: يجب أن يكون <code>switchOfStuff(&quot;b&quot;)</code> قيمة &quot;bird&quot;
    testString: 'assert(switchOfStuff("b") === "bird", "<code>switchOfStuff("b")</code> should have a value of "bird"");'
  - text: يجب أن يكون لـ <code>switchOfStuff(&quot;c&quot;)</code> قيمة &quot;cat&quot;
    testString: 'assert(switchOfStuff("c") === "cat", "<code>switchOfStuff("c")</code> should have a value of "cat"");'
  - text: يجب أن يكون لـ <code>switchOfStuff(&quot;d&quot;)</code> قيمة &quot;الأشياء&quot;
    testString: 'assert(switchOfStuff("d") === "stuff", "<code>switchOfStuff("d")</code> should have a value of "stuff"");'
  - text: يجب أن يكون <code>switchOfStuff(4)</code> قيمة &quot;الأشياء&quot;
    testString: 'assert(switchOfStuff(4) === "stuff", "<code>switchOfStuff(4)</code> should have a value of "stuff"");'
  - text: يجب عدم استخدام أي <code>if</code> أو <code>else</code> البيانات
    testString: 'assert(!/else/g.test(code) || !/if/g.test(code), "You should not use any <code>if</code> or <code>else</code> statements");'
  - text: يجب عليك استخدام العبارة <code>default</code>
    testString: 'assert(switchOfStuff("string-to-trigger-default-case") === "stuff", "You should use a <code>default</code> statement");'
  - text: يجب أن يكون لديك على الأقل 3 بيانات <code>break</code>
    testString: 'assert(code.match(/break/g).length > 2, "You should have at least 3 <code>break</code> statements");'

Challenge Seed

function switchOfStuff(val) {
  var answer = "";
  // Only change code below this line



  // Only change code above this line
  return answer;
}

// Change this value to test
switchOfStuff(1);

Solution

// solution required