Erreur dans programme
iamtheone
Messages postés
40
Statut
Membre
-
hcp7kuz Messages postés 238 Date d'inscription Statut Membre Dernière intervention -
hcp7kuz Messages postés 238 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
Je ne comprend vraiment pas. Voici mon code (pas très long don't worry). La question que je me pose est à la fin de celui-ci.
Merci bien.
Je ne comprend vraiment pas. Voici mon code (pas très long don't worry). La question que je me pose est à la fin de celui-ci.
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<style>
table {
background-color: blue;
}
td {
width: 50px;
height: 50px;
border: 5px solid blue;
border-radius: 100%;
background-color: white;
}
</style>
</head>
<body>
<table>
<tr>
<td onClick="testt(0)"></td>
<td onClick="testt(1)"></td>
<td onClick="testt(2)"></td>
</tr>
<tr>
<td onClick="testt(3)"></td>
<td onClick="testt(4)"></td>
<td onClick="testt(5)"></td>
</tr>
</table>
<script>
tour = -1;
function testt(i) {
td = document.getElementsByTagName("td")[i];
if (td.style.backgroundColor=="white") {
tour++;
if (tour%2==0) {
//si pair
td.style.backgroundColor = "red";
} else {
//si impair
td.style.backgroundColor = "yellow";
}
} else {
alert("Pourquoi je m'affiche toujours ?");
}
}
</script>
</body>
</html>
Merci bien.