Рок, бумажные ножницы JS [закрыто]Javascript

Форум по Javascript
Ответить
Anonymous
 Рок, бумажные ножницы JS [закрыто]

Сообщение 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();


Подробнее здесь: https://stackoverflow.com/questions/794 ... cissors-js
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Javascript»