I am having yet another issue with defining variables. It keeps saying that the variable is undefined. When printing it out it uses the array "rl" and targets the first string, then prints it. It does it repeatedly until it printed out the whole array one by one. When I change "rl[c]"(C is the current number in the array being printed out) to rl[1] or rl[2] it prints it out. When I print c it prints out the number of players... what? If you can help me that will be very appreciated. Javascript:
var al;
var rl;
var bd;
function gp(){
players = document.getElementById("input").value;
if(isNaN(players)){
alert(players.toUpperCase() + "'s Players? Please Fix");
return;
}
if(players === " "){
alert("Please Define How Many People Are Playing!");
return;
}
if(players === ""){
alert("Please Define How Many People Are Playing!");
return;
}
if(players < 4){
alert("Sorry, You Need Atleast 4 Players To Play!");
return;
}
SA(players)
}
function SA(players){
var positions = ["Murderer", "Judge", "Innocent", "Innocent"]; //Pre-set positions
if(players == 5){
positions.push("Co-Judge");
}else if(players == 6){
positions.push("Innocent", "Co-Judge");
}else if(players == 7){
positions.push("Murderer-2!", "Innocent", "Co-Judge");
}
Randomize(players, positions)
}
function shuffle(o){
for(var j, x, i = o.length; i; j = Math.floor(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
return o;
}
function Randomize(players, positions){
rl = shuffle(positions);
al = positions.length;
confirm("You Have: " + al + " Players, Correct?");
return rl;
}
var counter;
var c;
function DJ(){
var bd = 0;
for(var c = 0; c < al + 1; c++){
if(counter == 0){
var tz = c.value;
document.getElementById("DS").innerHTML=("You Are A: " + rl[tz]);
document.getElementById("DJ").innerHTML=("Click To Clear!");
counter = 1;
}else{
document.getElementById("DS").innerHTML=("Click 'Display Your Job!'");
document.getElementById("DJ").innerHTML=("Display Your Job!");
counter = 0;
}
}
}
HTML:
<html>
<head>
<link href="Styles.css" type="text/css" rel="stylesheet">
<script src="Javascript.js" language="javascript" type="text/javascript"></script>
<title>Miji</title>
</head>
<body>
<h1 id="mt">~*~ Miji ~*~</h1>
<div id="GetPlayers">
<input maxlength="1" id="input"> <button id="gp" onclick="gp()">Start!</button>
<br/>
<br/>
<button id="DJ" onclick="DJ();">Display Your Job!</button>
<br/>
<span id="DS">1) Input Amount Of Players. 2)Click 'Display Your Job!'</span>
</div>
</body>
</html>
Update: The tz = c.value was to test if c was being set to a string or something...