Please help me with this. I am not understanding what to do. Please fix the code to the display all contents of the image below. I DONT NEED IT TO DISPLAY ALL. ALL CONTENTS OF THE IMAGES ARE SHOWING EXECPT FOR WHEN IT GIVES THE RESULTS OF THE GAMES AT THE BOTTOM (e.g. Player 2 wins, etc.) HTML: Task 5 Rock, Paper, Scissors Play JAVASCRIPT: // Global variables to keep track of wins and losses let player1Wins = 0; let player2Wins = 0; let ties = 0; function playGame() { // Generate random numbers for player and computer const playerChoice = Math.floor(Math.random() * 3) + 1; const computerChoice = Math.floor(Math.random() * 3) + 1; // Convert the random numbers to text choices let playerTextChoice; let computerTextChoice; if (playerChoice === 1) { playerTextChoice = 'ROCK'; } else if (playerChoice === 2) { playerTextChoice = 'SCISSORS'; } else { playerTextChoice = 'PAPER'; } if (computerChoice === 1) { computerTextChoice = 'ROCK'; } else if (computerChoice === 2) { computerTextChoice = 'SCISSORS'; } else { computerTextChoice = 'PAPER'; } // Update the paragraph with player and computer choices const myData = document.getElementById('mydata'); myData.innerHTML = `Player 1 plays ${playerTextChoice} and Player 2 plays ${computerTextChoice}`; // Determine the winner let winner; if (playerChoice === computerChoice) { winner = 'Tie'; ties++; } else if (playerChoice === 1 && computerChoice === 3) { winner = 'Player 1 Wins!'; player1Wins++; } else if (playerChoice === 2 && computerChoice === 1) { winner = 'Player 1 Wins!'; player1Wins++; } else if (playerChoice === 3 && computerChoice === 2) { winner = 'Player 1 Wins!'; player1Wins++; } else { winner = 'Player 2 Wins!'; player2Wins++; } // Display the winner using an alert if it's not a tie if (winner !== 'Tie') { alert(winner); } else { alert('Tie!'); } // Display the tally alert(`Player 1 Wins: ${player1Wins}\nPlayer 2 Wins: ${player2Wins}\nTies: ${ties}`); }
Please help me with this. I am not understanding what to do. Please fix the code to the display all contents of the image below. I DONT NEED IT TO DISPLAY ALL. ALL CONTENTS OF THE IMAGES ARE SHOWING EXECPT FOR WHEN IT GIVES THE RESULTS OF THE GAMES AT THE BOTTOM (e.g. Player 2 wins, etc.) HTML: Task 5 Rock, Paper, Scissors Play JAVASCRIPT: // Global variables to keep track of wins and losses let player1Wins = 0; let player2Wins = 0; let ties = 0; function playGame() { // Generate random numbers for player and computer const playerChoice = Math.floor(Math.random() * 3) + 1; const computerChoice = Math.floor(Math.random() * 3) + 1; // Convert the random numbers to text choices let playerTextChoice; let computerTextChoice; if (playerChoice === 1) { playerTextChoice = 'ROCK'; } else if (playerChoice === 2) { playerTextChoice = 'SCISSORS'; } else { playerTextChoice = 'PAPER'; } if (computerChoice === 1) { computerTextChoice = 'ROCK'; } else if (computerChoice === 2) { computerTextChoice = 'SCISSORS'; } else { computerTextChoice = 'PAPER'; } // Update the paragraph with player and computer choices const myData = document.getElementById('mydata'); myData.innerHTML = `Player 1 plays ${playerTextChoice} and Player 2 plays ${computerTextChoice}`; // Determine the winner let winner; if (playerChoice === computerChoice) { winner = 'Tie'; ties++; } else if (playerChoice === 1 && computerChoice === 3) { winner = 'Player 1 Wins!'; player1Wins++; } else if (playerChoice === 2 && computerChoice === 1) { winner = 'Player 1 Wins!'; player1Wins++; } else if (playerChoice === 3 && computerChoice === 2) { winner = 'Player 1 Wins!'; player1Wins++; } else { winner = 'Player 2 Wins!'; player2Wins++; } // Display the winner using an alert if it's not a tie if (winner !== 'Tie') { alert(winner); } else { alert('Tie!'); } // Display the tally alert(`Player 1 Wins: ${player1Wins}\nPlayer 2 Wins: ${player2Wins}\nTies: ${ties}`); }
Chapter4: Making Decisions
Section: Chapter Questions
Problem 8E: In the game Rock paper Scissors, two players simultaneously choose one of three options: rock,...
Related questions
Question
Please help me with this. I am not understanding what to do. Please fix the code to the display all contents of the image below. I DONT NEED IT TO DISPLAY ALL. ALL CONTENTS OF THE IMAGES ARE SHOWING EXECPT FOR WHEN IT GIVES THE RESULTS OF THE GAMES AT THE BOTTOM (e.g. Player 2 wins, etc.)
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title> Task 5 </title>
<link href="style.css" type="text/css" rel="stylesheet">
<script src="task5.js"></script>
</head>
<body>
<div id="box">
<p style="font-family: monospace;" class="newdata"> Rock, Paper, Scissors </p>
<p></p>
<button id="button" onclick="playGame();"> Play </button>
<p></p>
<p style="font-family: monospace;" id="mydata" class="newdata"></p>
</div>
</body>
</html>
JAVASCRIPT:
// Global variables to keep track of wins and losses
let player1Wins = 0;
let player2Wins = 0;
let ties = 0;
function playGame() {
// Generate random numbers for player and computer
const playerChoice = Math.floor(Math.random() * 3) + 1;
const computerChoice = Math.floor(Math.random() * 3) + 1;
// Convert the random numbers to text choices
let playerTextChoice;
let computerTextChoice;
if (playerChoice === 1) {
playerTextChoice = 'ROCK';
} else if (playerChoice === 2) {
playerTextChoice = 'SCISSORS';
} else {
playerTextChoice = 'PAPER';
}
if (computerChoice === 1) {
computerTextChoice = 'ROCK';
} else if (computerChoice === 2) {
computerTextChoice = 'SCISSORS';
} else {
computerTextChoice = 'PAPER';
}
// Update the paragraph with player and computer choices
const myData = document.getElementById('mydata');
myData.innerHTML = `Player 1 plays ${playerTextChoice} and Player 2 plays ${computerTextChoice}`;
// Determine the winner
let winner;
if (playerChoice === computerChoice) {
winner = 'Tie';
ties++;
} else if (playerChoice === 1 && computerChoice === 3) {
winner = 'Player 1 Wins!';
player1Wins++;
} else if (playerChoice === 2 && computerChoice === 1) {
winner = 'Player 1 Wins!';
player1Wins++;
} else if (playerChoice === 3 && computerChoice === 2) {
winner = 'Player 1 Wins!';
player1Wins++;
} else {
winner = 'Player 2 Wins!';
player2Wins++;
}
// Display the winner using an alert if it's not a tie
if (winner !== 'Tie') {
alert(winner);
} else {
alert('Tie!');
}
// Display the tally
alert(`Player 1 Wins: ${player1Wins}\nPlayer 2 Wins: ${player2Wins}\nTies: ${ties}`);
}
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 3 steps with 1 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Operations Research : Applications and Algorithms
Computer Science
ISBN:
9780534380588
Author:
Wayne L. Winston
Publisher:
Brooks Cole
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Operations Research : Applications and Algorithms
Computer Science
ISBN:
9780534380588
Author:
Wayne L. Winston
Publisher:
Brooks Cole