Skip to content

Commit 32f9cc1

Browse files
author
Pretty Taruvinga
committed
restored the deleted file
1 parent ff3d1d3 commit 32f9cc1

File tree

5 files changed

+101
-0
lines changed

5 files changed

+101
-0
lines changed

Sprint-3/4-stretch/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# 🔍 Stretch
2+
3+
These stretch activities are not mandatory, but we hope you will explore them after you have completed the mandatory work.
4+
5+
In this exercise, you'll need to **play computer** with the function `find`. This function makes use of while loop statement. Your task will be to step through the code to figure out what is happening when the computer executes the code.
6+
7+
Next, try implementing the functions specified in `password-validator.js`.
8+
9+
Finally, set up your own script and test files for `card-validator.md`
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
## **PROJECT: Credit Card Validator**
2+
3+
In this project you'll write a script that validates whether or not a credit card number is valid.
4+
5+
Here are the rules for a valid number:
6+
7+
- Number must be 16 digits, all of them must be numbers.
8+
- You must have at least two different digits represented (all of the digits cannot be the same).
9+
- The final digit must be even.
10+
- The sum of all the digits must be greater than 16.
11+
12+
For example, the following credit card numbers are valid:
13+
14+
```markdown
15+
9999777788880000
16+
6666666666661666
17+
```
18+
19+
And the following credit card numbers are invalid:
20+
21+
```markdown
22+
a92332119c011112 (invalid characters)
23+
4444444444444444 (only one type of number)
24+
1111111111111110 (sum less than 16)
25+
6666666666666661 (odd final number)
26+
```
27+
28+
These are the requirements your project needs to fulfill:
29+
30+
- Make a JavaScript file with a name that describes its contents.
31+
- Create a function with a descriptive name which makes it clear what the function does. The function should take one argument, the credit card number to validate.
32+
- Write at least 2 comments that explain to others what a line of code is meant to do.
33+
- Return a boolean from the function to indicate whether the credit card number is valid.
34+
35+
Good luck!

Sprint-3/4-stretch/find.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
function find(str, char) {
2+
let index = 0;
3+
4+
while (index < str.length) {
5+
if (str[index] === char) {
6+
return index;
7+
}
8+
index++;
9+
}
10+
return -1;
11+
}
12+
13+
console.log(find("code your future", "u"));
14+
console.log(find("code your future", "z"));
15+
16+
// The while loop statement allows us to do iteration - the repetition of a certain number of tasks according to some condition
17+
// See the docs https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/while
18+
19+
// Use the Python Visualiser to help you play computer with this example and observe how this code is executed
20+
// Pay particular attention to the following:
21+
22+
// a) How the index variable updates during the call to find
23+
// b) What is the if statement used to check
24+
// c) Why is index++ being used?
25+
// d) What is the condition index < str.length used for?
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function passwordValidator(password) {
2+
return password.length < 5 ? false : true
3+
}
4+
5+
6+
module.exports = passwordValidator;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
Password Validation
3+
4+
Write a program that should check if a password is valid
5+
and returns a boolean
6+
7+
To be valid, a password must:
8+
- Have at least 5 characters.
9+
- Have at least one English uppercase letter (A-Z)
10+
- Have at least one English lowercase letter (a-z)
11+
- Have at least one number (0-9)
12+
- Have at least one of the following non-alphanumeric symbols: ("!", "#", "$", "%", ".", "*", "&")
13+
- Must not be any previous password in the passwords array.
14+
15+
You must breakdown this problem in order to solve it. Find one test case first and get that working
16+
*/
17+
const isValidPassword = require("./password-validator");
18+
test("password has at least 5 characters", () => {
19+
// Arrange
20+
const password = "12345";
21+
// Act
22+
const result = isValidPassword(password);
23+
// Assert
24+
expect(result).toEqual(true);
25+
}
26+
);

0 commit comments

Comments
 (0)