Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
W
webinar_11_AJS-13-14
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
Nikolay Tarassenko
webinar_11_AJS-13-14
Commits
426db68a
Commit
426db68a
authored
Feb 01, 2023
by
Nikolay Tarassenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Добавлено приложение quiz таблица умножения
parent
df116351
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
182 additions
and
0 deletions
+182
-0
index.js
example_2/js/index.js
+182
-0
No files found.
example_2/js/index.js
View file @
426db68a
// const userName = prompt('Как ваше имя?');
// alert(`Привет ${userName},\n\` как ваши дела?`);
const
userErrors
=
[
[
1
,
0
],
[
2
,
0
],
[
3
,
0
],
[
4
,
0
],
[
5
,
0
],
[
6
,
0
],
[
7
,
0
],
[
8
,
0
],
[
9
,
0
],
];
let
corretAnswer
=
0
;
let
wrongAnswer
=
0
;
let
questionCount
=
0
;
const
quizeMode
=
prompt
(
'Choose difficult mode, enter easy,normal,hard,all'
)
.
toLowerCase
()
.
trim
();
switch
(
quizeMode
)
{
case
'easy'
:
{
alert
(
'easy'
);
while
(
true
)
{
const
firstRandomValue
=
Math
.
floor
(
Math
.
random
()
*
2
+
1
);
const
secondRandomValue
=
Math
.
floor
(
Math
.
random
()
*
2
+
1
);
const
userAnswer
=
prompt
(
`What is
${
firstRandomValue
}
*
${
secondRandomValue
}
`
);
if
(
userAnswer
===
null
)
break
;
let
userNumber
=
parseInt
(
userAnswer
);
while
(
isNaN
(
userNumber
))
{
userNumber
=
parseInt
(
prompt
(
'You enter not a number, please enter number'
)
);
if
(
!
isNaN
(
userNumber
))
break
;
}
questionCount
++
;
if
(
userNumber
===
firstRandomValue
*
secondRandomValue
)
{
corretAnswer
++
;
}
else
{
wrongAnswer
++
;
userErrors
[
firstRandomValue
-
1
][
1
]
++
;
if
(
firstRandomValue
!==
secondRandomValue
)
{
userErrors
[
secondRandomValue
-
1
][
1
]
++
;
}
}
}
const
sortedErrors
=
userErrors
.
sort
((
a
,
b
)
=>
a
[
1
]
-
b
[
1
]).
slice
(
-
3
);
let
errorsMessage
=
''
;
for
(
let
i
=
0
;
i
<
sortedErrors
.
length
;
i
++
)
{
errorsMessage
+=
`Multyply by
${
sortedErrors
[
i
][
0
]}
: x
${
sortedErrors
[
i
][
1
]}
\n`
;
}
const
messageResult
=
`Question qty:
${
questionCount
}
\n`
+
`wrong answer qty:
${
wrongAnswer
}
\n`
+
`correct answer qty:
${
corretAnswer
}
\n`
+
errorsMessage
;
alert
(
messageResult
);
}
break
;
case
'normal'
:
{
alert
(
'normal'
);
while
(
true
)
{
const
firstRandomValue
=
Math
.
round
(
Math
.
random
()
*
(
5
-
3
)
+
3
);
const
secondRandomValue
=
Math
.
round
(
Math
.
random
()
*
(
5
-
3
)
+
3
);
const
userAnswer
=
prompt
(
`What is
${
firstRandomValue
}
*
${
secondRandomValue
}
`
);
if
(
userAnswer
===
null
)
break
;
let
userNumber
=
parseInt
(
userAnswer
);
while
(
isNaN
(
userNumber
))
{
userNumber
=
parseInt
(
prompt
(
'You enter not a number, please enter number'
)
);
if
(
!
isNaN
(
userNumber
))
break
;
}
questionCount
++
;
if
(
userNumber
===
firstRandomValue
*
secondRandomValue
)
{
corretAnswer
++
;
}
else
{
wrongAnswer
++
;
userErrors
[
firstRandomValue
-
1
][
1
]
++
;
if
(
firstRandomValue
!==
secondRandomValue
)
{
userErrors
[
secondRandomValue
-
1
][
1
]
++
;
}
}
}
const
sortedErrors
=
userErrors
.
sort
((
a
,
b
)
=>
a
[
1
]
-
b
[
1
]).
slice
(
-
3
);
let
errorsMessage
=
''
;
for
(
let
i
=
0
;
i
<
sortedErrors
.
length
;
i
++
)
{
errorsMessage
+=
`Multyply by
${
sortedErrors
[
i
][
0
]}
: x
${
sortedErrors
[
i
][
1
]}
\n`
;
}
const
messageResult
=
`Question qty:
${
questionCount
}
\n`
+
`wrong answer qty:
${
wrongAnswer
}
\n`
+
`correct answer qty:
${
corretAnswer
}
\n`
+
errorsMessage
;
alert
(
messageResult
);
}
break
;
case
'hard'
:
{
alert
(
'hard'
);
while
(
true
)
{
const
firstRandomValue
=
Math
.
round
(
Math
.
random
()
*
(
9
-
1
)
+
1
);
let
secondRandomValue
=
Math
.
round
(
Math
.
random
()
*
(
9
-
1
)
+
1
);
while
(
secondRandomValue
===
1
||
secondRandomValue
===
2
||
secondRandomValue
===
5
)
{
secondRandomValue
=
Math
.
round
(
Math
.
random
()
*
(
9
-
1
)
+
1
);
}
const
userAnswer
=
prompt
(
`What is
${
firstRandomValue
}
*
${
secondRandomValue
}
`
);
if
(
userAnswer
===
null
)
break
;
let
userNumber
=
parseInt
(
userAnswer
);
while
(
isNaN
(
userNumber
))
{
userNumber
=
parseInt
(
prompt
(
'You enter not a number, please enter number'
)
);
if
(
!
isNaN
(
userNumber
))
break
;
}
questionCount
++
;
if
(
userNumber
===
firstRandomValue
*
secondRandomValue
)
{
corretAnswer
++
;
}
else
{
wrongAnswer
++
;
userErrors
[
firstRandomValue
-
1
][
1
]
++
;
if
(
firstRandomValue
!==
secondRandomValue
)
{
userErrors
[
secondRandomValue
-
1
][
1
]
++
;
}
}
}
const
sortedErrors
=
userErrors
.
sort
((
a
,
b
)
=>
a
[
1
]
-
b
[
1
]).
slice
(
-
3
);
let
errorsMessage
=
''
;
for
(
let
i
=
0
;
i
<
sortedErrors
.
length
;
i
++
)
{
errorsMessage
+=
`Multyply by
${
sortedErrors
[
i
][
0
]}
: x
${
sortedErrors
[
i
][
1
]}
\n`
;
}
const
messageResult
=
`Question qty:
${
questionCount
}
\n`
+
`wrong answer qty:
${
wrongAnswer
}
\n`
+
`correct answer qty:
${
corretAnswer
}
\n`
+
errorsMessage
;
alert
(
messageResult
);
}
break
;
case
'all'
:
alert
(
'all'
);
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