javascript problem

so i decided to make a c++ forum bingo card in javascript. it worked fine except the generated card would keep repeating squares. i found the bug which was it wasnt marking ones that were already added. when i added that one line of code it stopped working. that line is commented out so you can tell where it is. why is it doing this?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<html>
	<head>
		<title>Forum Bingo!</title>

		<script type = "text/javascript">
			function load()
			{
				var idArray = ["b1", "i1", "n1", "g1", "o1", "b2", "i2", "n2", "g2", "o2", "b3", "i3", "n3",
					       "g3", "o3", "b4", "i4", "n4", "g4", "o4", "b5", "i5", "n5", "g5", "o5"];
				var square = ["Someone trolling", "Someone omitting the code tags",
					      "Someone looking for programming books to read", "Someone asking about a language besides c++",
					      "Someone posting in a wrong section", "Someone who has at least 5,500 posts",
					      "Someone wanting to add or asks about feature we don't have",
					      "Someone asking an obvious homework question", "Someone asking a question about a graphics library",
					      "Someone wanting to make a game", "Someone actually makes a game", "Someone has a username related to c++",
					      "Someone including c headers", "Someone starting a discussion about the star-pyramid generator",
					      "Someone making a program thats actually useful", "Someone referencing another post",
					      "Someone correcting someone else for omitting code tags", "Someone asking a socket-related question",
					      "Someone asking a question and is redirected to a tutorial", "Someone showing off ASCII art",
					      "Someone with code that can be written much better", "Someone showing code with horrible documentation",
					      "Someone posting an introduction", "Someone linking to pastebin",
					      "Someone asking a question about an embeddable langauge"];
				var valid = [true, true, true, true, true, true, true, true, true, true, true, true, true,
					     true, true, true, true, true, true, true, true, true, true, true, true];
				var counter, rand;

				for(counter = 0; counter < 25; counter++)
				{
					rand = Math.floor(Math.random() * 25);

					while(valid[rand] == false)
					{
						if(rand == 24)
						{
							rand = 0;
						}

						else if(rand != 0)
						{
							rand += 1;
						}

						else if(valid[rand] == true)
						{
							valid[rand] = false;
						}

					}

					//valid[rand] = false;

					document.getElementById(idArray[counter]).innerHTML = square[rand];
				}
			}
		</script>

		<style type = "text/css">
			table, td, th
			{
				border: solid 1px;
				border-spacing: 0px;
			}

			table
			{
				background-color: white;
			}

			body
			{
				background-color: rgb(0, 0, 0);
			}

			col
			{
				width: 150px;
			}

			.square
			{
				height: 120px;
			}
		</style>
	</head>

	<body onload = "load()">
		<table>
			<thead>
					<tr>
						<th>B</th>
						<th>I</th>
						<th>N</th>
						<th>G</th>
						<th>O</th>
					</tr>
			</thead>

			<col>
				<tr class = "square">
					<td id = "b1"></td>
					<td id = "i1"></td>
					<td id = "n1"></td>
					<td id = "g1"></td>
					<td id = "o1"></td>
				</tr>
			</col>

			<col>
				<tr class = "square">
					<td id = "b2"></td>
					<td id = "i2"></td>
					<td id = "n2"></td>
					<td id = "g2"></td>
					<td id = "o2"></td>
				</tr class = "square">
			</col>

			<col>
				<tr class = "square">
					<td id = "b3"></td>
					<td id = "i3"></td>
					<td id = "n3"></td>
					<td id = "g3"></td>
					<td id = "o3"></td>
				</tr>
			</col>

			<col>
					<tr class = "square">
						<td id = "b4"></td>
						<td id = "i4"></td>
						<td id = "n4"></td>
						<td id = "g4"></td>
						<td id = "o4"></td>
					</tr>
				</col>

				<col>
					<tr class = "square">
						<td id = "b5"></td>
						<td id = "i5"></td>
						<td id = "n5"></td>
						<td id = "g5"></td>
						<td id = "o5"></td>
					</tr>
				</col>
			</table>

		<button onclick = "load()">Load New Bingo Page</button><button>Print</button>
	</body>
</html>
Last edited on
Topic archived. No new replies allowed.