Im making a rock paper scissors game using js and html. Right now I'm having an issue with displaying the computers random choice. I created the text that appears purley through js with the .createElement method and it partially works. Right now this is what I'm getting:
I don't want to add a new line every time the player clicks a button. I just want to update the part with the orange box around it:
I have looked online for solutions but couldn't make sense of the solutions so any help with this would be greatly appreciated.
const getComputerChoice = () => {
let optionsArray = ["rock", "paper", "scissors"];
let randomNumber = Math.floor(Math.random() * optionsArray.length);
let compChoiceText = document.createElement("div");
compChoiceText.className = "font-light text-white text-4xl";
compChoiceText.innerHTML = `<p>
Computer chose: <span>${optionsArray[randomNumber]}</span>
</p>`;
document.getElementById("text-output-container").appendChild(compChoiceText);
};
const choice = document.querySelector(".buttons");
choice.addEventListener("click", (event) => {
getComputerChoice();
});
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>ROCK PAPER SCISSORS</title>
<meta name="description" content="" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="" />
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body>
<div class="w-full h-screen flex flex-col items-center justify-center bg-black gap-y-12">
<div id="text-output-container"></div>
<div class="buttons w-fit flex gap-x-10">
<button class="w-80 bg-cyan-500 shadow-lg shadow-cyan-500/50 text-white rounded text-6xl hover:bg-blue-500 hover:shadow-blue-500/50">
ROCK
</button>
<button class="w-80 bg-cyan-500 shadow-lg shadow-cyan-500/50 text-white rounded text-6xl hover:bg-blue-500 hover:shadow-blue-500/50">
PAPER
</button>
<button class="w-80 bg-cyan-500 shadow-lg shadow-cyan-500/50 text-white rounded text-6xl hover:bg-blue-500 hover:shadow-blue-500/50">
SCISSORS
</button>
</div>
</div>
<script src="script.js" async defer></script>
</body>
</html>

