Do you have more to say and show? You can do it in this section. Add pictures and a short description to show visitors more of whatever it is you want.
Add a description here.
Subscribed!
Thank you for subscribing to our newsletter.
// Define your number to text conversion schema with combinations
const numberToTextSchema = {
0: ['C', 'S', 'Z'],
1: ['T', 'D'],
2: ['N'],
3: ['M'],
4: ['R'],
5: ['L'],
6: ['J', 'G'],
7: ['K'],
8: ['F', 'V'],
9: ['B', 'P']
};
// Define special cases where certain combinations should equal "00"
const specialCases = {
'CS': '00',
'DZ': '00',
'DZS': '000', // Special case for DZS
'SZ': '00',
'ZS': '00'
};
// Function to generate all possible combinations for a given input number
function generateCombinations(input) {
if (input.length === 0) {
return [''];
}
const firstDigit = input[0];
const remainingInput = input.slice(1);
const possibleCombinations = numberToTextSchema[firstDigit] || ['Unknown'];
const combinations = [];
possibleCombinations.forEach(combination => {
const restCombinations = generateCombinations(remainingInput);
restCombinations.forEach(restCombination => {
const currentCombination = combination + restCombination;
const specialCaseReplacement = specialCases[currentCombination];
combinations.push(specialCaseReplacement || currentCombination);
});
});
return combinations;
}
// Function to convert text to numbers
function convertTextToNumbers(text) {
const digits = [];
for (let i = 0; i < text.length; i++) {
const char = text[i].toUpperCase();
for (const digit in numberToTextSchema) {
if (numberToTextSchema[digit].includes(char)) {
digits.push(digit);
break;
}
}
}
return digits.join('');
}
// Get elements from the DOM
const numberInput = document.getElementById('numberInput');
const textInput = document.getElementById('textInput');
const convertButton = document.getElementById('convertButton');
const result = document.getElementById('result');
// Add a click event listener to the convert button
convertButton.addEventListener('click', () => {
const inputNumber = numberInput.value;
const convertedText = generateCombinations(inputNumber);
const numCombinations = convertedText.length;
// Display results in "#### ####" format
const formattedResults = [];
convertedText.forEach((word, index) => {
if (index > 0 && index % 2 === 0) {
formattedResults.push(' '); // Add new line between pairs
}
formattedResults.push(word);
});
result.innerHTML = `Number to Text representation (number of combinations: ${numCombinations}):${formattedResults.join(' ')}`;
// Convert text to numbers
const inputText = textInput.value;
const convertedNumber = convertTextToNumbers(inputText);
result.innerHTML += `
Text to Number conversion: ${convertedNumber}`;
});