Style en javascrit

Résolu/Fermé
chabinot Messages postés 321 Date d'inscription mardi 10 novembre 2015 Statut Membre Dernière intervention 22 mars 2024 - 26 mars 2017 à 20:46
chabinot Messages postés 321 Date d'inscription mardi 10 novembre 2015 Statut Membre Dernière intervention 22 mars 2024 - 27 mars 2017 à 08:02
Bonjour,

Voilà mon code javascript :


const secondsHand = document.querySelector('.second-Hand');
const minsHand = document.querySelector('.min-Hand');
const hourHand = document.querySelector('.hour-Hand');

function setDate() {
const now = new Date();

const seconds = now.getSeconds();
const secondsDegrees = ((seconds / 60) * 360) + 90;
secondsHand.style.transform = `rotate(${secondsDegrees}deg)`;

const mins = now.getMinutes();
const minsDegrees = ((mins / 60) * 360) + 90;
minsHand.style.transform = `rotate(${minsDegrees}deg)`;

const hour= now.getHours();
const hourDegrees = ((hour / 12) * 360) + 90;
hourHand.style.transform = `rotate(${minsDegrees}deg)`;
}

setInterval(setDate, 1000);

J'ai une erreur à l'instruction :
secondsHand.style.transform = `rotate(${secondsDegrees}deg)`;

L'erreur est :
Uncaught TypeError: Cannot read property 'style' of null at setDat

Je vous mets également mon code html :
<!DOCTYPE html>
<html lang="fr">
<head>
	<meta charset="UTF-8">
	<title>Montre</title>
	<link rel="stylesheet" href="css/app.css">
</head>
<body>
	<div class="clock">
		<div class="clock-face">
			<div class="hand hour-hand"></div>
			<div class="hand min-hand"></div>
			<div class="hand second-hand"></div>
		</div>
	</div>
	
	<script src="js/app.js"></script>
</body>
</html>


J'ai beau cherhé, je ne vois pas où est l'erreur de codage.
Je vous remercie si quelqu'un a une idée d'où peut venir l'erreur.

2 réponses

proglib Messages postés 9 Date d'inscription vendredi 24 mars 2017 Statut Membre Dernière intervention 14 avril 2017 2
26 mars 2017 à 21:30
Salut
passe
const secondsHand = document.querySelector('.second-Hand');
const minsHand = document.querySelector('.min-Hand');
const hourHand = document.querySelector('.hour-Hand');

en
const secondsHand = document.querySelector('.second-hand');
const minsHand = document.querySelector('.min-hand');
const hourHand = document.querySelector('.hour-hand');

J'ai pas test ^^
0
chabinot Messages postés 321 Date d'inscription mardi 10 novembre 2015 Statut Membre Dernière intervention 22 mars 2024 15
27 mars 2017 à 08:02
Merci beaucoup,
Cela marche bien.
0