Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
Learning JavaScript
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MohammadAli Keshavarz
Learning JavaScript
Commits
7e2bc5a5
Commit
7e2bc5a5
authored
Oct 28, 2019
by
MohammadAli Keshavarz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add functionality for newGame btn
parent
a517dc4c
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
10 deletions
+37
-10
app.js
section3/app.js
+37
-10
No files found.
section3/app.js
View file @
7e2bc5a5
...
...
@@ -20,14 +20,34 @@ activePlayer = 0;
// var x = document.querySelector("#score-1").textContent;
// console.log(x);
// make dice invisible
document
.
querySelector
(
".dice"
).
style
.
display
=
"none"
;
// initializing user inteface
document
.
getElementById
(
"current-0"
).
textContent
=
"0"
;
document
.
getElementById
(
"current-1"
).
textContent
=
"0"
;
document
.
getElementById
(
"score-0"
).
textContent
=
"0"
;
document
.
getElementById
(
"score-1"
).
textContent
=
"0"
;
//initializing everything
init
();
function
init
()
{
// initializing global variable
scores
=
[
0
,
0
];
roundScore
=
0
;
activePlayer
=
0
;
// make dice invisible
document
.
querySelector
(
".dice"
).
style
.
display
=
"none"
;
// initializing user inteface
document
.
getElementById
(
"current-0"
).
textContent
=
"0"
;
document
.
getElementById
(
"current-1"
).
textContent
=
"0"
;
document
.
getElementById
(
"score-0"
).
textContent
=
"0"
;
document
.
getElementById
(
"score-1"
).
textContent
=
"0"
;
document
.
querySelector
(
".player-0-panel"
).
classList
.
remove
(
'active'
);
document
.
querySelector
(
".player-1-panel"
).
classList
.
remove
(
'active'
);
document
.
querySelector
(
".player-0-panel"
).
classList
.
remove
(
'winner'
);
document
.
querySelector
(
".player-1-panel"
).
classList
.
remove
(
'winner'
);
document
.
querySelector
(
".player-0-panel"
).
classList
.
add
(
'active'
);
document
.
getElementById
(
"name-0"
).
textContent
=
"PLAYER 1"
;
document
.
getElementById
(
"name-1"
).
textContent
=
"PLAYER 2"
;
}
function
changePlayer
()
{
roundScore
=
0
;
...
...
@@ -76,11 +96,18 @@ document.querySelector(".btn-hold").addEventListener("click", function() {
//find winner!
if
(
scores
[
activePlayer
]
>=
20
)
{
document
.
getElementById
(
"name-"
+
activePlayer
).
textContent
=
"Winner! :)"
;
document
.
querySelector
(
'.dice'
).
style
.
display
=
"none"
;
document
.
querySelector
(
".player-"
+
activePlayer
+
"-panel"
).
classList
.
remove
(
'active'
);
document
.
querySelector
(
".player-"
+
activePlayer
+
"-panel"
).
classList
.
add
(
'winner'
);
document
.
querySelector
(
".dice"
).
style
.
display
=
"none"
;
document
.
querySelector
(
".player-"
+
activePlayer
+
"-panel"
)
.
classList
.
remove
(
"active"
);
document
.
querySelector
(
".player-"
+
activePlayer
+
"-panel"
)
.
classList
.
add
(
"winner"
);
}
else
{
//change player
changePlayer
();
}
});
// add functionality for newGame btn
document
.
querySelector
(
'.btn-new'
).
addEventListener
(
"click"
,
init
);
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment