Commit 95000dc8 authored by Nurasyl's avatar Nurasyl

init

parent 77d0020f
// 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment