This is the exercise explanation:keyCoder test A

This test should take between 45 minutes and one hour to complete

To the right there is a diagram of a number pad. Each number, other than 0 and 1, has a series of letters associated with it.

Given a six-digit input number, write a PHP method to print all the possible six-letter words that can be made from the letters associated with each digit.

They may not be real-words in any particular language, just a string of characters.

As the digits 1 and 0 do not have letters as- sociated with them, input numbers that con- tain those digits should be rejected. The input to the method will be a string of characters, which must be validated.

Test cases we would like to use, to prove your code works:

Success – 234567 – (should return a list of six-letter words ADGJMP, BDGJMP, CDGJMP, AEGJMP, etc)

Failure – 123456 – invalid digit

Failure – 567890 – invalid digit Failure – 23456 – too few digits Failure – 2345678 – too many digits

This is the solution I made for this exercise, I used HTML, JavaScript and PHP all embedded in a single page.

The solution uses JavaScript to pre-check the output of the form in order to feed it in (by capturing a $_POST value) to the PHP part.

Leave a Reply

Your email address will not be published. Required fields are marked *