Satranç Tahtası Html Css JavaScript Kodu
<!DOCTYPE html>
<html>
<head>
<style>
table {
border-collapse: collapse;
}
td {
width: 50px;
height: 50px;
text-align: center;
vertical-align: middle;
}
.black {
background-color: black;
color: white;
}
.white {
background-color: white;
color: black;
}
</style>
</head>
<body>
<table id="chessBoard"></table>
<script>
const chessBoard = document.getElementById("chessBoard");
const pieces = ["R", "N", "B", "Q", "K", "B", "N", "R"];
for (let i = 0; i < 8; i++) {
const row = chessBoard.insertRow();
for (let j = 0; j < 8; j++) {
const cell = row.insertCell();
if ((i + j) % 2 === 0) {
cell.classList.add("white");
} else {
cell.classList.add("black");
}
if (i === 0 || i === 7) {
cell.textContent = pieces[j];
} else if (i === 1 || i === 6) {
cell.textContent = "P";
}
}
}
</script>
</body>
</html>
Yorumlar
Yorum Gönder