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

239
Vistas
Whats the best way to convert an integer to a string in the context of making a "Loot" simulator?

I'm a beginner in Javascript so please bare with me. What I have setup so far is a simple 6 sided dice. My goal is to assign each "side" to a number so that for instance if I roll a '6' , the 6 will print and have a value of "Dharoks Platebody".


    document.querySelector('#roll').addEventListener('click', roll)
    
    let num = 6
    
    function roll() {
    let diceRoll = Math.floor( Math.random() * 6 + 1)
    
    num.toString('Dharoks Platebody')
    alert(num)
    }

This is what I have so far but it returns the error "radix argument must be between 2 and 36" . Now obviously I could and likely will research that particular error more but my real question here is what is the most efficient way to go about this?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You are probably looking for an array:

const values = [
    "value if 1",
    "value if 2",
    "value if 3",
    "value if 4",
    "value if 5",
    "value if 6",
];

const num = Math.floor(Math.random() * 6) + 1;

alert(num);

alert(values[num - 1]);

There is a - 1 there because array indices start counting from 0. So the first item in the array would be the "0th position", and so on.

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