freeCodeCamp/curriculum/challenges/chinese/02-javascript-algorithms-an.../basic-algorithm-scripting/confirm-the-ending.chinese.md

3.4 KiB
Raw Blame History

id title isRequired challengeType videoUrl localeTitle
acda2fb1324d9b0fa741e6b5 Confirm the Ending true 5 确认结束

Description

检查字符串(第一个参数str )是否以给定的目标字符串(第二个参数, target )结束。这个挑战可以通过.endsWith()中引入的.endsWith()方法来解决。但是出于这个挑战的目的我们希望您使用其中一个JavaScript子字符串方法。如果卡住请记得使用Read-Search-Ask 。编写自己的代码。

Instructions

Tests

tests:
  - text: '<code>confirmEnding(&quot;Bastian&quot;, &quot;n&quot;)</code>应该返回true。'
    testString: assert(confirmEnding("Bastian", "n") === true);
  - text: '<code>confirmEnding(&quot;Congratulation&quot;, &quot;on&quot;)</code>应该返回true。'
    testString: assert(confirmEnding("Congratulation", "on") === true);
  - text: '<code>confirmEnding(&quot;Connor&quot;, &quot;n&quot;)</code>应返回false。'
    testString: assert(confirmEnding("Connor", "n") === false);
  - text: '<code>confirmEnding(&quot;Walking on water and developing software from a specification are easy if both are frozen&quot;, &quot;specification&quot;)</code>应该返回false。'
    testString: assert(confirmEnding("Walking on water and developing software from a specification are easy if both are frozen", "specification") === false);
  - text: '<code>confirmEnding(&quot;He has to give me a new name&quot;, &quot;name&quot;)</code>应该返回true。'
    testString: assert(confirmEnding("He has to give me a new name", "name") === true);
  - text: '<code>confirmEnding(&quot;Open sesame&quot;, &quot;same&quot;)</code>应该返回true。'
    testString: assert(confirmEnding("Open sesame", "same") === true);
  - text: '<code>confirmEnding(&quot;Open sesame&quot;, &quot;pen&quot;)</code>应该返回false。'
    testString: assert(confirmEnding("Open sesame", "pen") === false);
  - text: '<code>confirmEnding(&quot;Open sesame&quot;, &quot;game&quot;)</code>应该返回false。'
    testString: assert(confirmEnding("Open sesame", "game") === false);
  - text: '<code>confirmEnding(&quot;If you want to save our world, you must hurry. We dont know how much longer we can withstand the nothing&quot;, &quot;mountain&quot;)</code>应该返回虚假。'
    testString: assert(confirmEnding("If you want to save our world, you must hurry. We dont know how much longer we can withstand the nothing", "mountain") === false);
  - text: '<code>confirmEnding(&quot;Abstraction&quot;, &quot;action&quot;)</code>应该返回true。'
    testString: assert(confirmEnding("Abstraction", "action") === true);
  - text: 不要使用内置方法<code>.endsWith()</code>来解决挑战。
    testString: assert(!(/\.endsWith\(.*?\)\s*?;?/.test(code)) && !(/\['endsWith'\]/.test(code)));

Challenge Seed

function confirmEnding(str, target) {
  // "Never give up and good luck will find you."
  // -- Falcor
  return str;
}

confirmEnding("Bastian", "n");

Solution

// solution required