mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
feat(curriculum): add confirm string ending challenge (#61382)
This commit is contained in:
@@ -3143,6 +3143,12 @@
|
||||
"In this lab, you will practice truncating a string at a certain length."
|
||||
]
|
||||
},
|
||||
"lab-string-ending-checker": {
|
||||
"title": "Build a Confirm the Ending Tool",
|
||||
"intro": [
|
||||
"In this lab, you will implement a function that checks if a given string ends with a specified target string."
|
||||
]
|
||||
},
|
||||
"review-javascript-functions": {
|
||||
"title": "JavaScript Functions Review",
|
||||
"intro": [
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
---
|
||||
title: Introduction to the Build a Confirm the Ending Tool
|
||||
block: lab-string-ending-checker
|
||||
superBlock: full-stack-developer
|
||||
---
|
||||
|
||||
## Introduction to the Build a Confirm the Ending Tool
|
||||
|
||||
In this lab, you will implement a function that checks if a given string ends with a specified target string.
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "Build a Confirm the Ending Tool",
|
||||
"isUpcomingChange": false,
|
||||
"dashedName": "lab-string-ending-checker",
|
||||
"superBlock": "full-stack-developer",
|
||||
"helpCategory": "JavaScript",
|
||||
"challengeOrder": [{ "id": "acda2fb1324d9b0fa741e6b5", "title": "Build a Confirm the Ending Tool" }],
|
||||
"blockType": "lab",
|
||||
"blockLayout": "link",
|
||||
"usesMultifileEditor": true
|
||||
}
|
||||
+127
@@ -0,0 +1,127 @@
|
||||
---
|
||||
id: acda2fb1324d9b0fa741e6b5
|
||||
title: Build a Confirm the Ending Tool
|
||||
challengeType: 26
|
||||
dashedName: implement-a-string-ending-checker-function
|
||||
---
|
||||
|
||||
# --description--
|
||||
|
||||
In this lab, you will implement a function that checks if a string ends with the given target string.
|
||||
|
||||
**Objective:** Fulfill the user stories below and get all the tests to pass to complete the lab.
|
||||
|
||||
**User Stories:**
|
||||
|
||||
1. You should create a function named `confirmEnding` that takes two parameters: the string to check and the string to check against.
|
||||
2. The function should return `true` if the first string ends with the second string, and `false` otherwise.
|
||||
3. You should not use the `.endsWith()` method; instead, use one of the JavaScript substring methods to achieve this.
|
||||
|
||||
# --hints--
|
||||
|
||||
You should create a function named `confirmEnding`.
|
||||
|
||||
```js
|
||||
assert.isFunction(confirmEnding);
|
||||
```
|
||||
|
||||
`confirmEnding` should take 2 parameters.
|
||||
|
||||
```js
|
||||
assert.lengthOf(confirmEnding, 2);
|
||||
```
|
||||
|
||||
`confirmEnding("Bastian", "n")` should return `true`.
|
||||
|
||||
```js
|
||||
assert.isTrue(confirmEnding('Bastian', 'n'));
|
||||
```
|
||||
|
||||
`confirmEnding("Congratulation", "on")` should return `true`.
|
||||
|
||||
```js
|
||||
assert.isTrue(confirmEnding('Congratulation', 'on'));
|
||||
```
|
||||
|
||||
`confirmEnding("Connor", "n")` should return `false`.
|
||||
|
||||
```js
|
||||
assert.isFalse(confirmEnding('Connor', 'n'));
|
||||
```
|
||||
|
||||
`confirmEnding("Walking on water and developing software from a specification are easy if both are frozen", "specification")` should return `false`.
|
||||
|
||||
```js
|
||||
assert.isFalse(
|
||||
confirmEnding(
|
||||
'Walking on water and developing software from a specification are easy if both are frozen',
|
||||
'specification'
|
||||
)
|
||||
);
|
||||
```
|
||||
|
||||
`confirmEnding("He has to give me a new name", "name")` should return `true`.
|
||||
|
||||
```js
|
||||
assert.isTrue(confirmEnding('He has to give me a new name', 'name'));
|
||||
```
|
||||
|
||||
`confirmEnding("Open sesame", "same")` should return `true`.
|
||||
|
||||
```js
|
||||
assert.isTrue(confirmEnding('Open sesame', 'same'));
|
||||
```
|
||||
|
||||
`confirmEnding("Open sesame", "sage")` should return `false`.
|
||||
|
||||
```js
|
||||
assert.isFalse(confirmEnding('Open sesame', 'sage'));
|
||||
```
|
||||
|
||||
`confirmEnding("Open sesame", "game")` should return `false`.
|
||||
|
||||
```js
|
||||
assert.isFalse(confirmEnding('Open sesame', 'game'));
|
||||
```
|
||||
|
||||
`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.isFalse(
|
||||
confirmEnding(
|
||||
'If you want to save our world, you must hurry. We dont know how much longer we can withstand the nothing',
|
||||
'mountain'
|
||||
)
|
||||
);
|
||||
```
|
||||
|
||||
`confirmEnding("Abstraction", "action")` should return `true`.
|
||||
|
||||
```js
|
||||
assert.isTrue(confirmEnding('Abstraction', 'action'));
|
||||
```
|
||||
|
||||
Your code should not use the built-in method `.endsWith()` to solve the lab.
|
||||
|
||||
```js
|
||||
assert.notMatch(__helpers.removeJSComments(code), /\.endsWith\(.*?\)\s*?;?/);
|
||||
assert.notMatch(__helpers.removeJSComments(code), /\['endsWith'\]/);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
||||
```js
|
||||
function confirmEnding(str, target) {
|
||||
return str.substring(str.length - target.length) === target;
|
||||
}
|
||||
|
||||
confirmEnding('Bastian', 'n');
|
||||
```
|
||||
@@ -642,6 +642,9 @@
|
||||
{
|
||||
"dashedName": "lab-truncate-string"
|
||||
},
|
||||
{
|
||||
"dashedName": "lab-string-ending-checker"
|
||||
},
|
||||
{
|
||||
"dashedName": "review-javascript-functions"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user