Skip to content

Commit dfbdfe9

Browse files
committed
Added programs
0 parents  commit dfbdfe9

File tree

5 files changed

+163
-0
lines changed

5 files changed

+163
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Programming merit badge programs

finder.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Prgram to find a character in a string
2+
3+
look = "abcdefghijklmno"
4+
find = "a"
5+
6+
found = False
7+
8+
for i in range(len(look)):
9+
if (find == look[i]):
10+
found = True
11+
12+
if (found):
13+
print "Found it"
14+
else:
15+
print "Doesn't exist"

index.css

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
table {
2+
border-collapse: collapse;
3+
}
4+
table td, table td {
5+
border: 1px solid black;
6+
}
7+
table tr:first-child td {
8+
border-top: 0;
9+
}
10+
table tr:last-child td {
11+
border-bottom: 0;
12+
}
13+
table tr td:first-child,
14+
table tr th:first-child {
15+
border-left: 0;
16+
}
17+
table tr td:last-child,
18+
table tr th:last-child {
19+
border-right: 0;
20+
}
21+
22+
button {
23+
height: 40px;
24+
width: 40px;
25+
}

index.html

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Programming MB</title>
6+
7+
<script src="./index.js"></script>
8+
9+
<link rel="stylesheet" href="./index.css">
10+
11+
</head>
12+
13+
<body>
14+
15+
<h1>Programming Merit Badge Tic Tac Toe</h1>
16+
<table>
17+
<tr>
18+
<td><button id="r1c1" type="button" onclick='buttonClicked("r1c1")'></button></td>
19+
<td><button id="r1c2" type="button" onclick='buttonClicked("r1c2")'></button></td>
20+
<td><button id="r1c3" type="button" onclick='buttonClicked("r1c3")'></button></td>
21+
</tr>
22+
<tr>
23+
<td><button id="r2c1" type="button" onclick='buttonClicked("r2c1")'></button></td>
24+
<td><button id="r2c2" type="button" onclick='buttonClicked("r2c2")'></button></td>
25+
<td><button id="r2c3" type="button" onclick='buttonClicked("r2c3")'></button></td>
26+
</tr>
27+
<tr>
28+
<td><button id="r3c1" type="button" onclick='buttonClicked("r3c1")'></button></td>
29+
<td><button id="r3c2" type="button" onclick='buttonClicked("r3c2")'></button></td>
30+
<td><button id="r3c3" type="button" onclick='buttonClicked("r3c3")'></button></td>
31+
</tr>
32+
</table>
33+
34+
35+
</body>
36+
</html>
37+
38+
<!--onfocus='alert("Button clicked")' type="text" size="1"-->

index.js

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
var current = "X";
2+
3+
function has(id, check) {
4+
if (document.getElementById(id).innerHTML == check) {
5+
return true;
6+
}else{
7+
return false;
8+
}
9+
}
10+
11+
function checkWin(cur) {
12+
13+
var check = cur;
14+
15+
var one = "r1c1";
16+
var two = "r1c2";
17+
var three = "r1c3";
18+
19+
var four = "r2c1";
20+
var five = "r2c2";
21+
var six = "r2c3";
22+
23+
var seven = "r3c1";
24+
var eight = "r3c2";
25+
var nine = "r3c3";
26+
27+
var wins = false;
28+
29+
if (has(one, check) && has(two, check) && has(three, check)) {
30+
wins = true;
31+
}
32+
33+
if (has(four, check) && has(five, check) && has(six, check)) {
34+
wins = true;
35+
}
36+
37+
if (has(seven, check) && has(eight, check) && has(nine, check)) {
38+
wins = true;
39+
}
40+
41+
if (has(one, check) && has(four, check) && has(seven, check)) {
42+
wins = true;
43+
}
44+
45+
if (has(two, check) && has(five, check) && has(eight, check)) {
46+
wins = true;
47+
}
48+
49+
if (has(three, check) && has(six, check) && has(nine, check)) {
50+
wins = true;
51+
}
52+
53+
if (has(one, check) && has(five, check) && has(nine, check)) {
54+
wins = true;
55+
}
56+
57+
if (has(three, check) && has(five, check) && has(seven, check)) {
58+
wins = true;
59+
}
60+
61+
return wins;
62+
63+
}
64+
65+
function updateHTML(id) {
66+
document.getElementById(id).innerHTML = current;
67+
}
68+
69+
function buttonClicked(id) {
70+
updateHTML(id);
71+
document.getElementById(id).disabled = 'true';
72+
73+
setTimeout(function() {
74+
var won = checkWin(current);
75+
if (won) {
76+
alert(current + " wins!");
77+
}
78+
if (current == "X") {
79+
current = "O";
80+
}else{
81+
current = "X";
82+
}
83+
}, 100);
84+
}

0 commit comments

Comments
 (0)