You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: curriculum/challenges/english/02-javascript-algorithms-and-data-structures/javascript-algorithms-and-data-structures-projects/telephone-number-validator.md
Copy file name to clipboardExpand all lines: curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/build-a-telephone-number-validator-project/build-a-telephone-number-validator.md
+55Lines changed: 55 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -60,6 +60,8 @@ Note that the area code is required. Also, if the country code is provided, you
60
60
1. When `#user-input` contains `(555)5(55?)-5555` and `#check-btn` is clicked, `#results-div` should contain the text `"Invalid US number: (555)5(55?)-5555"`.
61
61
1. When the `#user-input` element contains `55 55-55-555-5` and the `#check-btn` element is clicked, the `#results-div` element should contain the text `"Invalid US number: 55 55-55-555-5"`.
62
62
1. When the `#user-input` element contains `11 555-555-5555` and the `#check-btn` element is clicked, the `#results-div` element should contain the text `"Invalid US number: 11 555-555-5555"`.
63
+
1. When the `#user-input` element contains a valid US number and the `#check-btn` element is clicked, the `#results-div` element should contain the text `"Valid US number: "` followed by the number.
64
+
1. When the `#user-input` element contains an invalid US number and the `#check-btn` element is clicked, the `#results-div` element should contain the text `"Invalid US number: "` followed by the number.
63
65
64
66
Fulfill the user stories and pass all the tests below to complete this project. Give it your own personal style. Happy Coding!
65
67
@@ -510,6 +512,59 @@ checkBtn.click();
510
512
assert.strictEqual(resultsDiv.innerText.trim().toLowerCase(), 'invalid us number: 11 555-555-5555');
511
513
```
512
514
515
+
When the `#user-input` element contains a valid US number and the `#check-btn` element is clicked, the `#results-div` element should contain the text `"Valid US number: "` followed by the number.
516
+
517
+
```js
518
+
519
+
constvalidPatterns= [
520
+
'1 XXX-XXX-XXXX',
521
+
'1 (XXX)XXX-XXXX',
522
+
'1(XXX)XXX-XXXX',
523
+
'1 XXX XXX XXXX',
524
+
'XXXXXXXXXX',
525
+
'XXX-XXX-XXXX',
526
+
'(XXX)XXX-XXXX',
527
+
];
528
+
529
+
validPatterns.forEach(pattern=> {
530
+
while (pattern.includes('X')) {
531
+
pattern =pattern.replace('X', Math.floor(Math.random() *7) +2); //While this may seem weird at first, it's required for the CI build to pass
532
+
//This is apparently because the solution provided for CI purposes actually checks for valid area and exchange codes.
533
+
}
534
+
resultsDiv.innerHTML='';
535
+
userInput.value= pattern;
536
+
userInput.dispatchEvent(newEvent('change'));
537
+
checkBtn.click();
538
+
assert.strictEqual(document.getElementById('results-div').innerText.trim().toLowerCase(), `valid us number: ${pattern}`);
539
+
});
540
+
```
541
+
542
+
When the `#user-input` element contains an invalid US number and the `#check-btn` element is clicked, the `#results-div` element should contain the text `"Invalid US number: "` followed by the number.
0 commit comments