--- id: acda2fb1324d9b0fa741e6b5 title: Confirm the Ending isRequired: true challengeType: 5 videoUrl: '' localeTitle: 确认结束 --- ## Description
检查字符串(第一个参数str )是否以给定的目标字符串(第二个参数, target )结束。这个挑战可以通过.endsWith()中引入的.endsWith()方法来解决。但是出于这个挑战的目的,我们希望您使用其中一个JavaScript子字符串方法。如果卡住,请记得使用Read-Search-Ask 。编写自己的代码。
## Instructions
## Tests
```yml tests: - text: 'confirmEnding("Bastian", "n")应该返回true。' testString: 'assert(confirmEnding("Bastian", "n") === true, "confirmEnding("Bastian", "n") should return true.");' - text: 'confirmEnding("Congratulation", "on")应该返回true。' testString: 'assert(confirmEnding("Congratulation", "on") === true, "confirmEnding("Congratulation", "on") should return true.");' - text: 'confirmEnding("Connor", "n")应返回false。' testString: 'assert(confirmEnding("Connor", "n") === false, "confirmEnding("Connor", "n") should return false.");' - text: 'confirmEnding("Walking on water and developing software from a specification are easy if both are frozen", "specification")应该返回false。' testString: 'assert(confirmEnding("Walking on water and developing software from a specification are easy if both are frozen", "specification") === false, "confirmEnding("Walking on water and developing software from a specification are easy if both are frozen", "specification") should return false.");' - text: 'confirmEnding("He has to give me a new name", "name")应该返回true。' testString: 'assert(confirmEnding("He has to give me a new name", "name") === true, "confirmEnding("He has to give me a new name", "name") should return true.");' - text: 'confirmEnding("Open sesame", "same")应该返回true。' testString: 'assert(confirmEnding("Open sesame", "same") === true, "confirmEnding("Open sesame", "same") should return true.");' - text: 'confirmEnding("Open sesame", "pen")应该返回false。' testString: 'assert(confirmEnding("Open sesame", "pen") === false, "confirmEnding("Open sesame", "pen") should return false.");' - text: 'confirmEnding("Open sesame", "game")应该返回false。' testString: 'assert(confirmEnding("Open sesame", "game") === false, "confirmEnding("Open sesame", "game") should return false.");' - text: 'confirmEnding("If you want to save our world, you must hurry. We dont know how much longer we can withstand the nothing", "mountain")应该返回虚假。' 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, "confirmEnding("If you want to save our world, you must hurry. We dont know how much longer we can withstand the nothing", "mountain") should return false.");' - text: 'confirmEnding("Abstraction", "action")应该返回true。' testString: 'assert(confirmEnding("Abstraction", "action") === true, "confirmEnding("Abstraction", "action") should return true.");' - text: 不要使用内置方法.endsWith()来解决挑战。 testString: 'assert(!(/\.endsWith\(.*?\)\s*?;?/.test(code)) && !(/\["endsWith"\]/.test(code)), "Do not use the built-in method .endsWith() to solve the challenge.");' ```
## Challenge Seed
```js function confirmEnding(str, target) { // "Never give up and good luck will find you." // -- Falcor return str; } confirmEnding("Bastian", "n"); ```
## Solution
```js // solution required ```