В настоящее время работает над моим первым проектом JS; Рок -бумага ножницы. Я обнаружил, что мои функции getComputerChoice () и Gethumanchocie бегут без проблем самостоятельно, однако следующие функции не дают ответа. Когда я запускаю всю программу сразу после того, как пользователь вводит свой выбор, больше ничего не происходит, консоль остается пустой без каких -либо ошибок или предупреждений в консоли. Функция Playround к концу программы, хотя я не уверен, что заставляет его не давать вывода, и не проходить через раунды. < /p>
let computerScore = 0
let round = 0
function getComputerChoice() {
let compChoice = Math.floor(Math.random() * 3) + 1;
// choosese a random number between 1 and 3.
if (compChoice === 1) {
compChoice = "rock";
}
if (compChoice === 2) {
compChoice = "paper";
}
if (compChoice === 3) {
compChoice === "scissors"
};
return compChoice;
};
function getHumanChoice() {
//Takes player choice of Rock, paper and scissors.
// will return players choice.
let humanChoice = prompt("Pick: Rock, paper or scissors! ").toLowerCase();
return humanChoice;
}
function playRound(humanChoice, compChoice) {
// increments the round winner's score and logs winner announcement.
if (//conditions for computer to win
humanChoice === "rock" && compChoice === "paper" ||
humanChoice === "paper" && compChoice === "scissors" ||
humanChoice === "scissors" && compChoice === "rock") {
computerScore = computerScore + 1;
return (`You lose ${compChoice} beats ${humanChoice}
computers gains a point!`)
} else if (// Conditions for player to win!
humanChoice === "rock" && compChoice === "scissors" ||
humanChoice == "paper" && compChoice === "rock" ||
humanChoice === "scissors" && compChoice === "paper") {
return (`You win. ${humanChoice} beats ${compChoice}.
You gain a point!`)
} else if (humanChoice === compChoice) { // condition if a tie
return (`It's a TIE!`)
} else { // Invalid selection
return (`Invalid selection, please try again!`)
};
};
const humanSelection = getHumanChoice();
const computerSelection = getComputerChoice();
playRound(humanSelection, computerSelection)
function playGame(playRound, round) { // 5 Rounds of Gameplay
if (round === 0) {
alert ("Round 1.....Show!")
playRound();
round = round +1;
} else if (round === 2) {
alert ("Round 2.....Show!")
playRound();
round = round +1;
} else if (round === 3) {
alert ("Round 3.....Show!")
playRound();
round = round +1;
} else if (round === 4) {
alert ("Round 4.....Show!")
playRound();
round = round +1;
} else if (round === 5) {
alert ("Round 5.....Show!")
playRound();
round = round +1;
} else if (round == 6) {
winner();
}
}
function winner (humanScore, computerScore) {
if (humanScore > computerScore) {
return (`YOU WIN! You have ${humanScore} points,
computer has ${computerScore} points`);
} else if (humanScore < computerScore) {
return (`Computer wins!, computer has ${computerScore} points
you have ${humanScore} points`);
} else {
return (`You Tie! Both you and computer have ${humanScore} points!`);
};
}
playRound();
Подробнее здесь: https://stackoverflow.com/questions/794 ... cissors-js
Рок, бумажные ножницы JS [закрыто] ⇐ Javascript
Форум по Javascript
1740074128
Anonymous
В настоящее время работает над моим первым проектом JS; Рок -бумага ножницы. Я обнаружил, что мои функции getComputerChoice () и Gethumanchocie бегут без проблем самостоятельно, однако следующие функции не дают ответа. Когда я запускаю всю программу сразу после того, как пользователь вводит свой выбор, больше ничего не происходит, консоль остается пустой без каких -либо ошибок или предупреждений в консоли. Функция Playround к концу программы, хотя я не уверен, что заставляет его не давать вывода, и не проходить через раунды. < /p>
let computerScore = 0
let round = 0
function getComputerChoice() {
let compChoice = Math.floor(Math.random() * 3) + 1;
// choosese a random number between 1 and 3.
if (compChoice === 1) {
compChoice = "rock";
}
if (compChoice === 2) {
compChoice = "paper";
}
if (compChoice === 3) {
compChoice === "scissors"
};
return compChoice;
};
function getHumanChoice() {
//Takes player choice of Rock, paper and scissors.
// will return players choice.
let humanChoice = prompt("Pick: Rock, paper or scissors! ").toLowerCase();
return humanChoice;
}
function playRound(humanChoice, compChoice) {
// increments the round winner's score and logs winner announcement.
if (//conditions for computer to win
humanChoice === "rock" && compChoice === "paper" ||
humanChoice === "paper" && compChoice === "scissors" ||
humanChoice === "scissors" && compChoice === "rock") {
computerScore = computerScore + 1;
return (`You lose ${compChoice} beats ${humanChoice}
computers gains a point!`)
} else if (// Conditions for player to win!
humanChoice === "rock" && compChoice === "scissors" ||
humanChoice == "paper" && compChoice === "rock" ||
humanChoice === "scissors" && compChoice === "paper") {
return (`You win. ${humanChoice} beats ${compChoice}.
You gain a point!`)
} else if (humanChoice === compChoice) { // condition if a tie
return (`It's a TIE!`)
} else { // Invalid selection
return (`Invalid selection, please try again!`)
};
};
const humanSelection = getHumanChoice();
const computerSelection = getComputerChoice();
playRound(humanSelection, computerSelection)
function playGame(playRound, round) { // 5 Rounds of Gameplay
if (round === 0) {
alert ("Round 1.....Show!")
playRound();
round = round +1;
} else if (round === 2) {
alert ("Round 2.....Show!")
playRound();
round = round +1;
} else if (round === 3) {
alert ("Round 3.....Show!")
playRound();
round = round +1;
} else if (round === 4) {
alert ("Round 4.....Show!")
playRound();
round = round +1;
} else if (round === 5) {
alert ("Round 5.....Show!")
playRound();
round = round +1;
} else if (round == 6) {
winner();
}
}
function winner (humanScore, computerScore) {
if (humanScore > computerScore) {
return (`YOU WIN! You have ${humanScore} points,
computer has ${computerScore} points`);
} else if (humanScore < computerScore) {
return (`Computer wins!, computer has ${computerScore} points
you have ${humanScore} points`);
} else {
return (`You Tie! Both you and computer have ${humanScore} points!`);
};
}
playRound();
Подробнее здесь: [url]https://stackoverflow.com/questions/79455428/rock-paper-scissors-js[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия