Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
C
classwork_24
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
Нұрасыл Қайратұлы
classwork_24
Commits
95000dc8
Commit
95000dc8
authored
Dec 15, 2023
by
Nurasyl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init
parent
77d0020f
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
79 additions
and
0 deletions
+79
-0
index.js
JS/index.js
+79
-0
No files found.
JS/index.js
View file @
95000dc8
// const initialList = ['John', 'Jack', 'Harry', 'Mario', 'Link', 'Zelda', 'Bowser'];
// const Host = {
// guestList: [],
// setGuestList: function(arr) {
// for(let i = 0; i < arr.length; i++) {
// const randomNum = Math.round(Math.random() * 100);
// if(randomNum < 20) {
// console.log(`${arr[i]} не очень.`);
// } else {
// this.guestList.push(arr[i]);
// };
// };
// },
// showList: function() {
// let str = this.guestList.join(", ");
// alert(`Список гостей: ${str}`);
// }
// };
// Host.setGuestList(initialList);
// Host.showList();
const
Game
=
{
initialWord
:
[
'John'
,
'Jack'
,
'Harry'
,
'Mario'
,
'Link'
,
'Zelda'
,
'Bowser'
],
currentWord
:
null
,
mysticWord
:
null
,
counter
:
0
,
setCurrentWord
:
function
()
{
const
randomNum
=
Math
.
round
(
Math
.
random
()
*
this
.
initialWord
.
length
-
1
);
const
str
=
this
.
initialWord
.
splice
(
randomNum
,
1
)[
0
];
this
.
currentWord
=
str
;
this
.
mysticWord
=
[];
for
(
let
i
=
0
;
i
<
this
.
currentWord
.
length
;
i
++
)
{
this
.
mysticWord
.
push
(
this
.
currentWord
[
i
]);
};
for
(
let
j
=
0
;
j
<
this
.
mysticWord
.
length
;
j
++
)
{
this
.
mysticWord
[
j
]
=
"_"
;
};
},
checked
:
function
(
answer
)
{
for
(
let
i
=
0
;
i
<
this
.
currentWord
.
length
;
i
++
)
{
if
(
this
.
currentWord
[
i
].
toLowerCase
()
===
answer
.
toLowerCase
())
this
.
mysticWord
[
i
]
=
answer
;
};
},
play
:
function
()
{
while
(
true
)
{
this
.
setCurrentWord
();
const
init
=
confirm
(
`Начать игру?`
);
if
(
init
===
false
)
break
;
while
(
true
)
{
const
answer
=
prompt
(
`Вот слово:
${
this
.
mysticWord
.
join
(
" "
)}
`
);
if
(
answer
===
null
)
break
;
this
.
counter
++
;
this
.
checked
(
answer
);
if
(
this
.
currentWord
.
toLowerCase
()
===
this
.
mysticWord
.
join
(
""
).
toLowerCase
())
{
alert
(
`вы угадали слово с
${
this
.
counter
}
попыток`
);
break
;
};
}
}
}
};
Game
.
play
();
\ 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