Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2021_123
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
2021_123
2021_123
Commits
070ec27b
Commit
070ec27b
authored
Oct 07, 2021
by
A.M.R.Y Bandara
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Multiplication game js file
parent
1d0ee318
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
152 additions
and
0 deletions
+152
-0
javascript.js
javascript.js
+152
-0
No files found.
javascript.js
0 → 100644
View file @
070ec27b
var
playing
=
false
;
var
score
;
var
timeRemaining
;
var
action
;
var
correctAnswer
;
document
.
getElementById
(
"
start
"
).
onclick
=
function
(){
if
(
playing
==
true
){
location
.
reload
();
}
else
{
document
.
getElementById
(
"
startgame
"
).
pause
();
playing
=
true
;
score
=
0
;
document
.
getElementById
(
"
scoreNumber
"
).
innerHTML
=
score
;
show
(
"
time
"
);
timeRemaining
=
30
;
document
.
getElementById
(
"
remainingTime
"
).
innerHTML
=
timeRemaining
;
hide
(
"
gameover
"
);
document
.
getElementById
(
"
start
"
).
innerHTML
=
"
Reset Game
"
;
startCountdown
();
generateQA
();
}
}
for
(
var
i
=
1
;
i
<
5
;
i
++
){
document
.
getElementById
(
"
answer
"
+
i
).
onclick
=
function
(){
if
(
playing
==
true
){
if
(
this
.
innerHTML
==
correctAnswer
)
{
score
++
;
document
.
getElementById
(
"
scoreNumber
"
).
innerHTML
=
score
;
document
.
getElementById
(
"
win
"
).
play
();
show
(
"
right
"
);
setTimeout
(
function
(){
hide
(
"
right
"
);
},
1000
);
hide
(
"
wrong
"
);
generateQA
();
}
else
{
document
.
getElementById
(
"
lost
"
).
play
();
show
(
"
wrong
"
);
setTimeout
(
function
(){
hide
(
"
wrong
"
);
},
1000
)
hide
(
"
right
"
);
}
}
}
}
function
startCountdown
(){
action
=
setInterval
(
function
(){
timeRemaining
-=
1
;
document
.
getElementById
(
"
remainingTime
"
).
innerHTML
=
timeRemaining
;
if
(
timeRemaining
==
0
)
{
stopCountdown
();
show
(
"
gameover
"
);
document
.
getElementById
(
"
gameover
"
).
innerHTML
=
"
<p>GAME OVER!</p><p>YOUR SCORE:
"
+
score
+
"
</p>
"
;
document
.
getElementById
(
"
final
"
).
play
();
hide
(
"
time
"
);
hide
(
"
right
"
);
hide
(
"
wrong
"
);
playing
=
false
;
document
.
getElementById
(
"
start
"
).
innerHTML
=
"
Start Game
"
;
}
},
1000
);
}
function
generateQA
(){
var
randomNumber1
=
Math
.
round
(
Math
.
random
()
*
10
);
var
randomNumber2
=
Math
.
round
(
Math
.
random
()
*
10
);
document
.
getElementById
(
"
problem
"
).
innerHTML
=
randomNumber1
+
"
x
"
+
randomNumber2
;
correctAnswer
=
randomNumber1
*
randomNumber2
;
var
answerBox
=
(
Math
.
round
(
Math
.
random
()
*
3
))
+
1
;
document
.
getElementById
(
"
answer
"
+
answerBox
).
innerHTML
=
correctAnswer
;
var
answers
=
[
correctAnswer
];
for
(
var
i
=
1
;
i
<
5
;
i
++
)
{
if
(
i
!==
answerBox
)
{
var
wrongAnswer
;
do
{
wrongAnswer
=
(
Math
.
round
(
Math
.
random
()
*
10
))
*
(
Math
.
round
(
Math
.
random
()
*
10
));
}
while
(
answers
.
indexOf
(
wrongAnswer
)
>-
1
)
document
.
getElementById
(
"
answer
"
+
i
).
innerHTML
=
wrongAnswer
;
answers
.
push
(
wrongAnswer
);
}
}
}
function
stopCountdown
(){
clearInterval
(
action
);
}
function
hide
(
id
){
document
.
getElementById
(
id
).
style
.
display
=
"
none
"
;
}
function
show
(
id
){
document
.
getElementById
(
id
).
style
.
display
=
"
block
"
;
}
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