Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

139
Vistas
coding numbers into letters With HTML/Javascript

I am looking for a way to code numbers into letters. I want to take an inputted django variable and flip the numbers to letters using the following:

1=M
2=A
3=k
4=E
etc.

What is the best way to complete this? I have looked at the switch function, but I can only seem to get it to work for 1 character. How would I get it to switch each number outputted from a Django variable?

    <script type="text/javascript"> 
       function myFunction() {
      var text;
      var Number = {{ Label.MetaData.price|number_format(0, '', '')|raw }};
      switch(Number) {
        case "1": text = "M"; break;
        case "2": text = "A"; break;
        case "3": text = "K"; break;
        case "4": text = "E"; break;
        }
        document.getElementById("code").innerHTML = text; }
    </script>
    <p id="code"></p>
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Using an object is probably the easiest way. Here's an example.

const letterMap = {
  " ": 0,
  a: 1,
  b: 2,
  c: 3,
  d: 4,
  e: 5,
  f: 6,
  g: 7,
  h: 8,
  i: 9,
  j: 10,
  k: 11,
  l: 12,
  m: 13,
  n: 14,
  o: 15,
  p: 16,
  q: 17,
  r: 18,
  s: 19,
  t: 20,
  u: 21,
  v: 22,
  w: 23,
  x: 24,
  y: 25,
  z: 26,
}

const sentence = "the quick brown fox jumped over the lazy dog"
for (const char of sentence) console.log(letterMap[char]);

about 4 years ago · Juan Pablo Isaza Denunciar

0

Edit: Replaced single quotes.

const characterString = 'MAKE';

const myNumber = 2  // replace with yours

const myLetter = characterString.charAt(myNumber);  // K

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda