Skip to content

Instantly share code, notes, and snippets.

@csim
Last active November 23, 2015 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save csim/10286010 to your computer and use it in GitHub Desktop.
Save csim/10286010 to your computer and use it in GitHub Desktop.
Clock Problem Solution
var angle = function(hour, minute) {
var hourAngle = parseFloat(hour * 30);
// take into account the movement of the hour hand between hours
hourAngle = hourAngle + parseFloat((minute / 60) * 5);
var minuteAngle = parseFloat(minute * 6);
var angle = Math.abs(hourAngle - minuteAngle);
return (angle > 180) ? 360 - angle : angle;
};
alert(angle(3, 0));
alert(angle(3, 10));
alert(angle(3, 30));
alert(angle(3, 40));
alert(angle(8, 33));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment