2018-10-04 14:37:37 +01:00
---
id: acda2fb1324d9b0fa741e6b5
title: Confirm the Ending
challengeType: 5
2019-07-31 11:32:23 -07:00
forumTopicId: 16006
2018-10-04 14:37:37 +01:00
---
2020-11-27 19:02:05 +01:00
# --description--
2018-10-04 14:37:37 +01:00
2020-11-27 19:02:05 +01:00
Check if a string (first argument, `str` ) ends with the given target string (second argument, `target` ).
This challenge *can* be solved with the `.endsWith()` method, which was introduced in ES2015. But for the purpose of this challenge, we would like you to use one of the JavaScript substring methods instead.
# --hints--
`confirmEnding("Bastian", "n")` should return true.
```js
assert(confirmEnding('Bastian', 'n') === true);
2018-10-04 14:37:37 +01:00
```
2020-11-27 19:02:05 +01:00
`confirmEnding("Congratulation", "on")` should return true.
2018-10-04 14:37:37 +01:00
2020-11-27 19:02:05 +01:00
```js
assert(confirmEnding('Congratulation', 'on') === true);
```
2018-10-04 14:37:37 +01:00
2020-11-27 19:02:05 +01:00
`confirmEnding("Connor", "n")` should return false.
2018-10-04 14:37:37 +01:00
```js
2020-11-27 19:02:05 +01:00
assert(confirmEnding('Connor', 'n') === false);
```
2018-10-04 14:37:37 +01:00
2020-11-27 19:02:05 +01:00
`confirmEnding("Walking on water and developing software from a specification are easy if both are frozen", "specification")` should return false.
```js
assert(
confirmEnding(
'Walking on water and developing software from a specification are easy if both are frozen',
'specification'
) === false
);
```
`confirmEnding("He has to give me a new name", "name")` should return true.
```js
assert(confirmEnding('He has to give me a new name', 'name') === true);
2018-10-04 14:37:37 +01:00
```
2020-11-27 19:02:05 +01:00
`confirmEnding("Open sesame", "same")` should return true.
```js
assert(confirmEnding('Open sesame', 'same') === true);
```
2018-10-04 14:37:37 +01:00
2020-11-27 19:02:05 +01:00
`confirmEnding("Open sesame", "sage")` should return false.
2018-10-04 14:37:37 +01:00
2020-11-27 19:02:05 +01:00
```js
assert(confirmEnding('Open sesame', 'sage') === false);
```
2018-10-04 14:37:37 +01:00
2020-11-27 19:02:05 +01:00
`confirmEnding("Open sesame", "game")` should return false.
2018-10-04 14:37:37 +01:00
2020-11-27 19:02:05 +01:00
```js
assert(confirmEnding('Open sesame', 'game') === false);
```
2018-10-04 14:37:37 +01:00
2020-11-27 19:02:05 +01:00
`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.
```js
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("Abstraction", "action")` should return true.
```js
assert(confirmEnding('Abstraction', 'action') === true);
```
Your code should not use the built-in method `.endsWith()` to solve the challenge.
```js
assert(!/\.endsWith\(.*?\)\s*?;?/.test(code) && !/\['endsWith'\]/.test(code));
```
# --seed--
## --seed-contents--
2018-10-04 14:37:37 +01:00
```js
function confirmEnding(str, target) {
2020-11-27 19:02:05 +01:00
return str;
2018-10-04 14:37:37 +01:00
}
confirmEnding("Bastian", "n");
```
2020-11-27 19:02:05 +01:00
# --solutions--
```js
function confirmEnding(str, target) {
return str.substring(str.length - target.length) === target;
}
confirmEnding("Bastian", "n");
```