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?
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.