2018-10-10 18:03:03 -04:00
---
id: acda2fb1324d9b0fa741e6b5
title: Confirm the Ending
isRequired: true
challengeType: 5
videoUrl: ''
localeTitle: 确认结束
---
## Description
2020-06-30 01:51:26 -07:00
<section id="description">检查字符串(第一个参数<code>str</code> )是否以给定的目标字符串(第二个参数, <code>target</code> )结束。这个挑战<em>可以</em>通过<code>.endsWith()</code>中引入的<code>.endsWith()</code>方法来解决。但是出于这个挑战的目的, 我们希望您使用其中一个JavaScript子字符串方法。如果卡住, 请记得使用<a href="https://forum.freecodecamp.org/t/how-to-get-help-when-you-are-stuck-coding/19514" target="_blank">Read-Search-Ask</a> 。编写自己的代码。 </section>
2018-10-10 18:03:03 -04:00
## Instructions
<section id="instructions">
</section>
## Tests
<section id='tests'>
```yml
tests:
- text: '<code>confirmEnding("Bastian", "n")</code>应该返回true。'
2020-02-18 01:40:55 +09:00
testString: assert(confirmEnding("Bastian", "n") === true);
2018-10-10 18:03:03 -04:00
- text: '<code>confirmEnding("Congratulation", "on")</code>应该返回true。'
2020-02-18 01:40:55 +09:00
testString: assert(confirmEnding("Congratulation", "on") === true);
2018-10-10 18:03:03 -04:00
- text: '<code>confirmEnding("Connor", "n")</code>应返回false。'
2020-02-18 01:40:55 +09:00
testString: assert(confirmEnding("Connor", "n") === false);
2018-10-10 18:03:03 -04:00
- text: '<code>confirmEnding("Walking on water and developing software from a specification are easy if both are frozen", "specification")</code>应该返回false。'
2020-02-18 01:40:55 +09:00
testString: assert(confirmEnding("Walking on water and developing software from a specification are easy if both are frozen", "specification") === false);
2018-10-10 18:03:03 -04:00
- text: '<code>confirmEnding("He has to give me a new name", "name")</code>应该返回true。'
2020-02-18 01:40:55 +09:00
testString: assert(confirmEnding("He has to give me a new name", "name") === true);
2018-10-10 18:03:03 -04:00
- text: '<code>confirmEnding("Open sesame", "same")</code>应该返回true。'
2020-02-18 01:40:55 +09:00
testString: assert(confirmEnding("Open sesame", "same") === true);
2018-10-10 18:03:03 -04:00
- text: '<code>confirmEnding("Open sesame", "pen")</code>应该返回false。'
2020-02-18 01:40:55 +09:00
testString: assert(confirmEnding("Open sesame", "pen") === false);
2018-10-10 18:03:03 -04:00
- text: '<code>confirmEnding("Open sesame", "game")</code>应该返回false。'
2020-02-18 01:40:55 +09:00
testString: assert(confirmEnding("Open sesame", "game") === false);
2018-10-10 18:03:03 -04:00
- text: '<code>confirmEnding("If you want to save our world, you must hurry. We dont know how much longer we can withstand the nothing", "mountain")</code>应该返回虚假。'
2020-02-18 01:40:55 +09:00
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);
2018-10-10 18:03:03 -04:00
- text: '<code>confirmEnding("Abstraction", "action")</code>应该返回true。'
2020-02-18 01:40:55 +09:00
testString: assert(confirmEnding("Abstraction", "action") === true);
2018-10-10 18:03:03 -04:00
- text: 不要使用内置方法<code>.endsWith()</code>来解决挑战。
2020-02-18 01:40:55 +09:00
testString: assert(!(/\.endsWith\(.*?\)\s*?;?/.test(code)) && !(/\['endsWith'\]/.test(code)));
2018-10-10 18:03:03 -04:00
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
function confirmEnding(str, target) {
// "Never give up and good luck will find you."
// -- Falcor
return str;
}
confirmEnding("Bastian", "n");
```
</div>
</section>
## Solution
<section id='solution'>
```js
// solution required
```
2020-08-13 17:24:35 +02:00
/section>