Well, i have been trying to make a die roller where the user selects a 4 sided d
up vote
-1
down vote
favorite
So, I have been trying to make a dice roller. So the user selects how many sides it has, and then how many of those dice to roll, for example two 10 sided dice. Then the system makes a random number in between one and the amount of sides the selected die has.
So here is what I did:
<input type="numbers" name="dieAmount" value="Type Die Amount Here">
<select id="dieType">
<option value="0"> Select Die Type</option>
<option value="20"> d20 </option>
<option value="12"> d12 </option>
<option value="10"> d10 </option>
<option value="8"> d8 </option>
<option value="6"> d6 </option>
<option value="4"> d4 </option>
<option value="2"> d2 </option>
</select>
<p>
<input type="button" value="Roll" onclick="roll(dieType)" />
</form>
<script>
function roll(){
var min= 1;
var max = document.getElementById("dieType").value;
var random = Math.floor(Math.random() * (+max - +min)) + min
var factor = document.getElementById("dieAmount").value;
var outcome = random * factor - 1
document.write("Number Rolled: " + outcome);
}
</script>
I just can't figure out how to make the select and input blocks to become a variable.
javascript html variables
add a comment |
up vote
-1
down vote
favorite
So, I have been trying to make a dice roller. So the user selects how many sides it has, and then how many of those dice to roll, for example two 10 sided dice. Then the system makes a random number in between one and the amount of sides the selected die has.
So here is what I did:
<input type="numbers" name="dieAmount" value="Type Die Amount Here">
<select id="dieType">
<option value="0"> Select Die Type</option>
<option value="20"> d20 </option>
<option value="12"> d12 </option>
<option value="10"> d10 </option>
<option value="8"> d8 </option>
<option value="6"> d6 </option>
<option value="4"> d4 </option>
<option value="2"> d2 </option>
</select>
<p>
<input type="button" value="Roll" onclick="roll(dieType)" />
</form>
<script>
function roll(){
var min= 1;
var max = document.getElementById("dieType").value;
var random = Math.floor(Math.random() * (+max - +min)) + min
var factor = document.getElementById("dieAmount").value;
var outcome = random * factor - 1
document.write("Number Rolled: " + outcome);
}
</script>
I just can't figure out how to make the select and input blocks to become a variable.
javascript html variables
1
"I just can't figure out how to make the select and sum=bmit blocks become a variable." No clue what you are asking.
– epascarello
Nov 20 at 13:39
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
So, I have been trying to make a dice roller. So the user selects how many sides it has, and then how many of those dice to roll, for example two 10 sided dice. Then the system makes a random number in between one and the amount of sides the selected die has.
So here is what I did:
<input type="numbers" name="dieAmount" value="Type Die Amount Here">
<select id="dieType">
<option value="0"> Select Die Type</option>
<option value="20"> d20 </option>
<option value="12"> d12 </option>
<option value="10"> d10 </option>
<option value="8"> d8 </option>
<option value="6"> d6 </option>
<option value="4"> d4 </option>
<option value="2"> d2 </option>
</select>
<p>
<input type="button" value="Roll" onclick="roll(dieType)" />
</form>
<script>
function roll(){
var min= 1;
var max = document.getElementById("dieType").value;
var random = Math.floor(Math.random() * (+max - +min)) + min
var factor = document.getElementById("dieAmount").value;
var outcome = random * factor - 1
document.write("Number Rolled: " + outcome);
}
</script>
I just can't figure out how to make the select and input blocks to become a variable.
javascript html variables
So, I have been trying to make a dice roller. So the user selects how many sides it has, and then how many of those dice to roll, for example two 10 sided dice. Then the system makes a random number in between one and the amount of sides the selected die has.
So here is what I did:
<input type="numbers" name="dieAmount" value="Type Die Amount Here">
<select id="dieType">
<option value="0"> Select Die Type</option>
<option value="20"> d20 </option>
<option value="12"> d12 </option>
<option value="10"> d10 </option>
<option value="8"> d8 </option>
<option value="6"> d6 </option>
<option value="4"> d4 </option>
<option value="2"> d2 </option>
</select>
<p>
<input type="button" value="Roll" onclick="roll(dieType)" />
</form>
<script>
function roll(){
var min= 1;
var max = document.getElementById("dieType").value;
var random = Math.floor(Math.random() * (+max - +min)) + min
var factor = document.getElementById("dieAmount").value;
var outcome = random * factor - 1
document.write("Number Rolled: " + outcome);
}
</script>
I just can't figure out how to make the select and input blocks to become a variable.
javascript html variables
javascript html variables
edited Nov 20 at 13:51
MarcoS
8,9151663130
8,9151663130
asked Nov 20 at 13:38
Alessandro Hidalgo
63
63
1
"I just can't figure out how to make the select and sum=bmit blocks become a variable." No clue what you are asking.
– epascarello
Nov 20 at 13:39
add a comment |
1
"I just can't figure out how to make the select and sum=bmit blocks become a variable." No clue what you are asking.
– epascarello
Nov 20 at 13:39
1
1
"I just can't figure out how to make the select and sum=bmit blocks become a variable." No clue what you are asking.
– epascarello
Nov 20 at 13:39
"I just can't figure out how to make the select and sum=bmit blocks become a variable." No clue what you are asking.
– epascarello
Nov 20 at 13:39
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
You only missed to define an id
attribute for dieAmount (and you don't need a name
attribute there)... And, you can't access the select current value simply by value, but you should use the element's option selectedIndex...
See my code:
<input type="numbers" id="dieAmount" value="Type Die Amount Here">
<select id="dieType">
<option value="0"> Select Die Type</option>
<option value="20"> d20 </option>
<option value="12"> d12 </option>
<option value="10"> d10 </option>
<option value="8"> d8 </option>
<option value="6"> d6 </option>
<option value="4"> d4 </option>
<option value="2"> d2 </option>
</select>
<p>
<input type="button" value="Roll" onclick="roll(dieType)" />
<script>
function roll() {
var factor = document.getElementById("dieAmount").value;
var dieTypeElement = document.getElementById("dieType");
var max = dieTypeElement.options[dieTypeElement.selectedIndex].value;
var min = 1;
var random = Math.floor(Math.random() * (max - min)) + min;
var outcome = random * factor - 1;
document.write("Number Rolled: " + outcome);
}
</script>
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53394282%2fwell-i-have-been-trying-to-make-a-die-roller-where-the-user-selects-a-4-sided-d%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
You only missed to define an id
attribute for dieAmount (and you don't need a name
attribute there)... And, you can't access the select current value simply by value, but you should use the element's option selectedIndex...
See my code:
<input type="numbers" id="dieAmount" value="Type Die Amount Here">
<select id="dieType">
<option value="0"> Select Die Type</option>
<option value="20"> d20 </option>
<option value="12"> d12 </option>
<option value="10"> d10 </option>
<option value="8"> d8 </option>
<option value="6"> d6 </option>
<option value="4"> d4 </option>
<option value="2"> d2 </option>
</select>
<p>
<input type="button" value="Roll" onclick="roll(dieType)" />
<script>
function roll() {
var factor = document.getElementById("dieAmount").value;
var dieTypeElement = document.getElementById("dieType");
var max = dieTypeElement.options[dieTypeElement.selectedIndex].value;
var min = 1;
var random = Math.floor(Math.random() * (max - min)) + min;
var outcome = random * factor - 1;
document.write("Number Rolled: " + outcome);
}
</script>
add a comment |
up vote
0
down vote
accepted
You only missed to define an id
attribute for dieAmount (and you don't need a name
attribute there)... And, you can't access the select current value simply by value, but you should use the element's option selectedIndex...
See my code:
<input type="numbers" id="dieAmount" value="Type Die Amount Here">
<select id="dieType">
<option value="0"> Select Die Type</option>
<option value="20"> d20 </option>
<option value="12"> d12 </option>
<option value="10"> d10 </option>
<option value="8"> d8 </option>
<option value="6"> d6 </option>
<option value="4"> d4 </option>
<option value="2"> d2 </option>
</select>
<p>
<input type="button" value="Roll" onclick="roll(dieType)" />
<script>
function roll() {
var factor = document.getElementById("dieAmount").value;
var dieTypeElement = document.getElementById("dieType");
var max = dieTypeElement.options[dieTypeElement.selectedIndex].value;
var min = 1;
var random = Math.floor(Math.random() * (max - min)) + min;
var outcome = random * factor - 1;
document.write("Number Rolled: " + outcome);
}
</script>
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
You only missed to define an id
attribute for dieAmount (and you don't need a name
attribute there)... And, you can't access the select current value simply by value, but you should use the element's option selectedIndex...
See my code:
<input type="numbers" id="dieAmount" value="Type Die Amount Here">
<select id="dieType">
<option value="0"> Select Die Type</option>
<option value="20"> d20 </option>
<option value="12"> d12 </option>
<option value="10"> d10 </option>
<option value="8"> d8 </option>
<option value="6"> d6 </option>
<option value="4"> d4 </option>
<option value="2"> d2 </option>
</select>
<p>
<input type="button" value="Roll" onclick="roll(dieType)" />
<script>
function roll() {
var factor = document.getElementById("dieAmount").value;
var dieTypeElement = document.getElementById("dieType");
var max = dieTypeElement.options[dieTypeElement.selectedIndex].value;
var min = 1;
var random = Math.floor(Math.random() * (max - min)) + min;
var outcome = random * factor - 1;
document.write("Number Rolled: " + outcome);
}
</script>
You only missed to define an id
attribute for dieAmount (and you don't need a name
attribute there)... And, you can't access the select current value simply by value, but you should use the element's option selectedIndex...
See my code:
<input type="numbers" id="dieAmount" value="Type Die Amount Here">
<select id="dieType">
<option value="0"> Select Die Type</option>
<option value="20"> d20 </option>
<option value="12"> d12 </option>
<option value="10"> d10 </option>
<option value="8"> d8 </option>
<option value="6"> d6 </option>
<option value="4"> d4 </option>
<option value="2"> d2 </option>
</select>
<p>
<input type="button" value="Roll" onclick="roll(dieType)" />
<script>
function roll() {
var factor = document.getElementById("dieAmount").value;
var dieTypeElement = document.getElementById("dieType");
var max = dieTypeElement.options[dieTypeElement.selectedIndex].value;
var min = 1;
var random = Math.floor(Math.random() * (max - min)) + min;
var outcome = random * factor - 1;
document.write("Number Rolled: " + outcome);
}
</script>
answered Nov 20 at 13:46
MarcoS
8,9151663130
8,9151663130
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53394282%2fwell-i-have-been-trying-to-make-a-die-roller-where-the-user-selects-a-4-sided-d%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
"I just can't figure out how to make the select and sum=bmit blocks become a variable." No clue what you are asking.
– epascarello
Nov 20 at 13:39