-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathscript.js
More file actions
67 lines (49 loc) · 1.21 KB
/
script.js
File metadata and controls
67 lines (49 loc) · 1.21 KB
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
var board = {
topRow:{
col1:"x",
col2:"o",
col3:"."
},
middleRow:{
col1:".",
col2:".",
col3:"."
},
bottomRow:{
col1:".",
col2:".",
col3:"."
}
};
// HOW TO PRINT OUR THE STATE OF THE GAME
var boardOutput = "";
// loop through each row
for( var rowKey in board ){
/*
* make a variable for convenience
* a shortcut so you won't have
* to write board[rowKey][columnKey]
*/
var row = board[rowKey];
// loop through each column
for( var columnKey in row ){
// concatenate the string together
boardOutput = boardOutput + row[columnKey];
}
// make a newline so that each row begins on a new line
boardOutput = boardOutput + "\n";
}
console.log( boardOutput );
// set a variable that represents
// whether or not the game is currently running
var running = false;
// run the game on a loop
while( running ){
var row = prompt("enter your row: topRow, middleRow or bottomRow");
var column = prompt("enter your column: col1, col2, col3");
console.log("current value @: ", board[row][column] );
// you can also use the break statement to get out of a while loop
break;
// if all spaces are filled, end game
// if game is won, end game
}