Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
lab_20
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
Vladislav Rybalko
lab_20
Commits
21577f1e
Commit
21577f1e
authored
May 08, 2024
by
Vladislav Rybalko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
done task 4
parents
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
215 additions
and
0 deletions
+215
-0
index.html
index.html
+13
-0
main.js
js/main.js
+202
-0
No files found.
index.html
0 → 100644
View file @
21577f1e
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<meta
charset=
"UTF-8"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0"
>
<title>
Document
</title>
</head>
<body>
<script
src=
"js/main.js"
></script>
</body>
</html>
\ No newline at end of file
js/main.js
0 → 100644
View file @
21577f1e
const
userErrors
=
new
Array
(
9
).
fill
(
0
)
let
correctAnswer
=
0
let
wrongAnswer
=
0
let
questionCount
=
0
const
quizMode
=
prompt
(
'Choose difficult mode:
\
neasy
\
nnormal
\
nhard
\
nall'
)
if
(
quizMode
!==
null
)
{
quizMode
.
toLowerCase
().
trim
()
}
switch
(
quizMode
)
{
case
'easy'
:
alert
(
'easy'
)
while
(
true
)
{
const
firstRandomNum
=
Math
.
floor
(
Math
.
random
()
*
2
+
1
)
const
secondRandomNum
=
Math
.
floor
(
Math
.
random
()
*
2
+
1
)
const
userAnswer
=
prompt
(
`What is
${
firstRandomNum
}
*
${
secondRandomNum
}
`
)
if
(
userAnswer
===
null
)
break
;
const
userNum
=
parseInt
(
userAnswer
)
if
(
!
isNaN
(
userNum
))
{
questionCount
++
if
(
userNum
===
firstRandomNum
*
secondRandomNum
)
{
correctAnswer
++
}
else
{
wrongAnswer
++
userErrors
[
firstRandomNum
-
1
]
++
if
(
firstRandomNum
!==
secondRandomNum
)
{
userErrors
[
secondRandomNum
-
1
]
++
}
};
}
else
{
alert
(
'You enter invalid value!'
)
}
}
let
errorMessage
=
''
for
(
let
i
=
0
;
i
<
userErrors
.
length
;
i
++
)
{
errorMessage
+=
`Multiplay by
${
i
+
1
}
=
${
userErrors
[
i
]}
\n`
}
const
messageResult
=
`Total question:
${
questionCount
}
\nCorrect answer:
${
correctAnswer
}
\nWrong answer
${
wrongAnswer
}
\n
${
errorMessage
}
`
alert
(
messageResult
)
break
;
case
'normal'
:
{
alert
(
'normal'
)
while
(
true
)
{
const
firstRandomNum
=
Math
.
floor
(
Math
.
random
()
*
3
+
3
)
const
secondRandomNum
=
Math
.
floor
(
Math
.
random
()
*
3
+
3
)
const
userAnswer
=
prompt
(
`What is
${
firstRandomNum
}
*
${
secondRandomNum
}
`
)
if
(
userAnswer
===
null
)
break
;
const
userNum
=
parseInt
(
userAnswer
)
if
(
!
isNaN
(
userNum
))
{
questionCount
++
if
(
userNum
===
firstRandomNum
*
secondRandomNum
)
{
correctAnswer
++
}
else
{
wrongAnswer
++
userErrors
[
firstRandomNum
-
1
]
++
if
(
firstRandomNum
!==
secondRandomNum
)
{
userErrors
[
secondRandomNum
-
1
]
++
}
};
}
else
{
alert
(
'You enter invalid value!'
)
}
}
let
errorMessage
=
''
for
(
let
i
=
0
;
i
<
userErrors
.
length
;
i
++
)
{
errorMessage
+=
`Multiplay by
${
i
+
1
}
=
${
userErrors
[
i
]}
\n`
}
const
messageResult
=
`Total question:
${
questionCount
}
\nCorrect answer:
${
correctAnswer
}
\nWrong answer
${
wrongAnswer
}
\n
${
errorMessage
}
`
alert
(
messageResult
)
}
break
;
case
'hard'
:
{
alert
(
'hard'
)
while
(
true
)
{
let
firstRandomNum
=
1
while
(
firstRandomNum
===
1
||
firstRandomNum
===
2
||
firstRandomNum
===
5
)
{
firstRandomNum
=
Math
.
floor
(
Math
.
random
()
*
9
+
1
)
}
let
secondRandomNum
=
1
while
(
secondRandomNum
===
1
||
secondRandomNum
===
2
||
secondRandomNum
===
5
)
{
secondRandomNum
=
Math
.
floor
(
Math
.
random
()
*
9
+
1
)
}
const
userAnswer
=
prompt
(
`What is
${
firstRandomNum
}
*
${
secondRandomNum
}
`
)
if
(
userAnswer
===
null
)
break
;
const
userNum
=
parseInt
(
userAnswer
)
if
(
!
isNaN
(
userNum
))
{
questionCount
++
if
(
userNum
===
firstRandomNum
*
secondRandomNum
)
{
correctAnswer
++
}
else
{
wrongAnswer
++
userErrors
[
firstRandomNum
-
1
]
++
if
(
firstRandomNum
!==
secondRandomNum
)
{
userErrors
[
secondRandomNum
-
1
]
++
}
};
}
else
{
alert
(
'You enter invalid value!'
)
}
}
let
errorMessage
=
''
for
(
let
i
=
0
;
i
<
userErrors
.
length
;
i
++
)
{
errorMessage
+=
`Multiplay by
${
i
+
1
}
=
${
userErrors
[
i
]}
\n`
}
const
messageResult
=
`Total question:
${
questionCount
}
\nCorrect answer:
${
correctAnswer
}
\nWrong answer
${
wrongAnswer
}
\n
${
errorMessage
}
`
alert
(
messageResult
)
}
break
;
case
'all'
:
{
alert
(
'all'
)
while
(
true
)
{
const
firstRandomNum
=
Math
.
floor
(
Math
.
random
()
*
9
+
1
)
const
secondRandomNum
=
Math
.
floor
(
Math
.
random
()
*
9
+
1
)
const
userAnswer
=
prompt
(
`What is
${
firstRandomNum
}
*
${
secondRandomNum
}
`
)
if
(
userAnswer
===
null
)
break
;
const
userNum
=
parseInt
(
userAnswer
)
if
(
!
isNaN
(
userNum
))
{
questionCount
++
if
(
userNum
===
firstRandomNum
*
secondRandomNum
)
{
correctAnswer
++
}
else
{
wrongAnswer
++
userErrors
[
firstRandomNum
-
1
]
++
if
(
firstRandomNum
!==
secondRandomNum
)
{
userErrors
[
secondRandomNum
-
1
]
++
}
};
}
else
{
alert
(
'You enter invalid value!'
)
}
}
let
errorMessage
=
''
const
countErr
=
[]
for
(
let
i
=
0
;
i
<
userErrors
.
length
;
i
++
)
{
countErr
.
push
({
[
i
+
1
]:
userErrors
[
i
]})
}
const
sortedError
=
countErr
.
sort
((
a
,
b
)
=>
a
[
Object
.
keys
(
a
)[
0
]]
-
b
[
Object
.
keys
(
b
)[
0
]]).
slice
(
-
3
)
for
(
let
i
=
0
;
i
<
sortedError
.
length
;
i
++
)
{
const
key
=
Object
.
keys
(
sortedError
[
i
])[
0
]
const
value
=
sortedError
[
i
][
key
]
errorMessage
+=
`Multiplay by
${
key
}
=
${
value
}
\n`
}
const
messageResult
=
`Total question:
${
questionCount
}
\nCorrect answer:
${
correctAnswer
}
\nWrong answer
${
wrongAnswer
}
\n
${
errorMessage
}
`
alert
(
messageResult
)
}
break
;
case
null
:
alert
(
'End game'
)
break
;
default
:
alert
(
'You enter invalid value, setting default mode, all'
)
break
;
}
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