Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

217
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!