← Back to challenges

Phone Number Word Decoder

JavaScriptHardformattinglanguage_fundamentalsstringsregex

Instructions

Create a program that converts a phone number with letters to one with only numbers.

NumberLetter
0none
1none
2ABC
3DEF
4GHI
5JKL
6MNO
7PQRS
8TUV
9WXYZ

Examples

textToNum("123-647-EYES") ➞ "123-647-3937"

textToNum("(325)444-TEST") ➞ "(325)444-8378"

textToNum("653-TRY-THIS") ➞ "653-879-8447"

textToNum("435-224-7613") ➞ "435-224-7613"

Notes

  • All inputs will be formatted as a string representing a proper phone number in the format XXX-XXX-XXXX or (XXX)XXX-XXXX, using numbers and capital letters.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.