Fix and reorganize this whole code

<html>
<button onclick = "leftmove()" id = "b1"> Left </button>
<button onclick = "rightmove()" id = "b2"> Right </button>
<button onclick = "upmove()" id = "b3"> Up </button>
<button onclick = "downmove()" id = "b4"> Down </button>
<h1 id = "box"></h1>
<style type = "text/css">
#box {
width: 50px;
height: 50px;
background-color: black;
}

<script>
var box = document.getElementById("box");
function leftmove() {
margin += 2;
box.style.marginLeft = margin + "px";
}
var box = document.getElementById("box");
function rightmove() {
margin -= 2;
box.style.marginLeft = margin + "px";
}
var box = document.getElementById("box");
function upmove() {
margin += 2;
box.style.marginTop = margin + "px";
}
var box = document.getElementById("box");
function downmove() {
margin -= 2;
box.style.marginLeft = margin + "px";
}
</script>
</html>

<html>
<button onclick = "leftmove()" id = "b1"> Left </button>
<button onclick = "rightmove()" id = "b2"> Right </button>
<button onclick = "upmove()" id = "b3"> Up </button>
<button onclick = "downmove()" id = "b4"> Down </button>
<h1 id = "box"></h1>
<style type = "text/css">
#box {
width: 50px;
height: 50px;
background-color: black;
}

<script>
var box = document.getElementById("box");
function leftmove() {
margin += 2;
box.style.marginLeft = margin + "px";
}
var box = document.getElementById("box");
function rightmove() {
margin -= 2;
box.style.marginLeft = margin + "px";
}
var box = document.getElementById("box");
function upmove() {
margin += 2;
box.style.marginTop = margin + "px";
}
var box = document.getElementById("box");
function downmove() {
margin -= 2;
box.style.marginLeft = margin + "px";
}
</script>
</html>

<!DOCTYPE html>
<html>
<head>
<title>Guess What</title>
</head>
<body>
<div id="page1">
<h1>Welcome to Guess What!</h1>
<p>
In this game, you will be presented with a question and three options to
choose from. Your goal is to select the correct answer and see how many
you can get right.
</p>
<button onclick="startGame()">Start Game</button>
</div>

<div id="page2" style="display: none">
<h2>Question: What is the capital of France?</h2>
<input type="radio" id="optionA" name="answer" value="Madrid" /> A)
Madrid<br />
<input type="radio" id="optionB" name="answer" value="Berlin" /> B)
Berlin<br />
<input type="radio" id="optionC" name="answer" value="Paris" /> C)
Paris<br />
<button onclick="submitAnswer()">Submit</button>
<button onclick="endGame()">End Game</button>
</div>

<script>
let correctAnswer = "Paris";

function startGame() {
document.getElementById("page1").style.display = "none";
document.getElementById("page2").style.display = "block";
<!DOCTYPE html>
<html>
<head>
<title>Guess What</title>
</head>
<body>
<div id="page1">
<h1>Welcome to Guess What!</h1>
<p>
In this game, you will be presented with a question and three options to
choose from. Your goal is to select the correct answer and see how many
you can get right.
</p>
<button onclick="startGame()">Start Game</button>
</div>

<div id="page2" style="display: none">
<h2>Question: What is the capital of France?</h2>
<input type="radio" id="optionA" name="answer" value="Madrid" /> A)
Madrid<br />
<input type="radio" id="optionB" name="answer" value="Berlin" /> B)
Berlin<br />
<input type="radio" id="optionC" name="answer" value="Paris" /> C)
Paris<br />
<button onclick="submitAnswer()">Submit</button>
<button onclick="endGame()">End Game</button>
</div>

<script>
let correctAnswer = "Paris";

// Function to start the game
function startGame() {
document.getElementById("page1").style.display = "none";
document.getElementById("page2").style.display = "block";
}

}

function submitAnswer() {
let selectedAnswer = document.querySelector(
'input[name="answer"]:checked'
).value;
if (selectedAnswer === correctAnswer) {
alert("Correct! The capital of France is Paris.");
} else {
alert("Incorrect. The correct answer is Paris.");
}
document.getElementById("page1").style.display = "block";
document.getElementById("page2").style.display = "none";
}

function endGame() {
document.getElementById("page1").style.display = "block";
document.getElementById("page2").style.display = "none";
}
</script>
</body>
</html>

<!DOCTYPE html>

<html>
<head>
<title>Guess What</title>
</head>
<body>
<div id="page1">
<h1>Welcome to Guess What!</h1>
<p>
In this game, you will be presented with a question and three options to
choose from. Your goal is to select the correct answer and see how many
you can get right.
</p>
<button onclick="startGame()">Start Game</button>
</div>

<div id="page2" style="display: none">
<h2>Question: What is the capital of France?</h2>
<input type="radio" id="optionA" name="answer" value="Madrid" /> A) Madrid<br />
<input type="radio" id="optionB" name="answer" value="Berlin" /> B) Berlin<br />
<input type="radio" id="optionC" name="answer" value="Paris" /> C) Paris<br />
<button onclick="submitAnswer()">Submit</button>
<button onclick="endGame()">End Game</button>
</div>

<script>
let correctAnswer = "Paris";

function startGame() {
document.getElementById("page1").style.display = "none";
document.getElementById("page2").style.display = "block";
}

function submitAnswer() {
let selectedAnswer = document.querySelector('input[name="answer"]:checked').value;
if (selectedAnswer === correctAnswer) {
alert("Correct! The capital of France is Paris.");
} else {
alert("Incorrect. The correct answer is Paris.");
}
document.getElementById("page1").style.display = "block";
document.getElementById("page2").style.display = "none";
}

function endGame() {
document.getElementById("page1").style.display = "block";
document.getElementById("page2").style.display = "none";
}
</script>
</body>
</html>