# Khan/khan-exercises

### Subversion checkout URL

You can clone with
or
.
Fetching contributors…
Cannot retrieve contributors at this time
352 lines (303 sloc) 10.8 KB
 Telling time 2
randRange( 1, 12 ) 15 randRange( 0, (60 / MINUTE_INCREMENT) - 1 ) * MINUTE_INCREMENT
MINUTE === 0 MINUTE > 5 ? MINUTE : "0" + MINUTE HOUR + ":" + NICE_MINUTE

Set the clock to TIME. The hour hand is blue and the minute hand is orange.

Drag the two hands so the clock reads HOUR:NICE_MINUTE.
[ minutePoint.coord, hourPoint.coord ]
var minuteAngle = cartToPolar( guess[0] )[1]; var hourAngle = cartToPolar( guess[1] )[1]; minuteAngle = roundToNearest( minuteSnapDegrees, minuteAngle ); hourAngle = roundToNearest( hourSnapDegrees, hourAngle ); // if hands have not been moved, return `""` if ( minuteAngle === minuteStartAngle && hourAngle === hourStartAngle) { return ""; } return (minuteAngle === correctMinuteAngle) && (hourAngle === correctHourAngle);
minutePoint.moveTo( guess[0][0], guess[0][1], true ); hourPoint.moveTo( guess[1][0], guess[1][1], true );

The number after the \Large{:} symbol represents the number of minutes past the hour. So TIME represents MINUTE minutes past hour HOUR.

First, let's set the minute hand.

Each long tick mark is an increment of 5 minutes, because 60 minutes / 12 tick marks = 5 minutes per tick mark.

Since we are MINUTE minutes past the hour, the minute hand should be at the mark numbered 12, which is the first tick mark on the clock and represents 0 minutes past the hourand there are 5 minutes per tick mark, the minute hand should be at the mark numbered fraction(MINUTE, 5) = MINUTE/5.

Next, let's set the hour hand.

The 12 long tick marks correspond to the hours in the day (assuming AM/PM time).

If it is 0 minutes, the hour hand belongs directly on the corresponding hour mark. However, for any other number of minutes, the hour hand should be proportionally past the hour mark.

Since it's HOUR hourplural(HOUR) and 0 minutes, the hour hand should be right on the HOUR hour mark.

Since it's HOUR hourplural(HOUR) and MINUTE minutes, the hour hand should be fraction(MINUTE, 60) = fraction(MINUTE, 60, false, true) of the way past the HOUR hour mark.

var minuteRadius = minutePoint.constraints.fixedDistance.dist; var hourRadius = hourPoint.constraints.fixedDistance.dist; var minuteCoord = polar( minuteRadius, correctMinuteAngle ); var hourCoord = polar( hourRadius, correctHourAngle ); var dotOpacity = 0.4; var handOpacity = 0.3; addMovableLineSegment({ coordA: minuteCoord, coordZ: [ 0, 0 ], fixed: true, normalStyle: { stroke: ORANGE, "stroke-width": 10, "stroke-dasharray": ".", "stroke-linecap": "round", "stroke-opacity": dotOpacity }, }); addMovableLineSegment({ coordA: minuteCoord, coordZ: [ 0, 0 ], fixed: true, normalStyle: { stroke: ORANGE, "stroke-width": 10, "stroke-linecap": "round", "stroke-opacity": handOpacity }, }); addMovableLineSegment({ coordA: hourCoord, coordZ: [ 0, 0 ], fixed: true, normalStyle: { stroke: BLUE, "stroke-width": 10, "stroke-dasharray": ".", "stroke-linecap": "round", "stroke-opacity": dotOpacity }, }); addMovableLineSegment({ coordA: hourCoord, coordZ: [ 0, 0 ], fixed: true, normalStyle: { stroke: BLUE, "stroke-width": 10, "stroke-linecap": "round", "stroke-opacity": handOpacity }, }); // for some reason this doesn't work, so for now, create another center point // centerPoint.toFront(); addMovablePoint({ coord: [ 0, 0 ], constraints: { fixed: true }, normalStyle: { fill: "#fff", stroke: "#000", "stroke-dasharray": "", "stroke-width": 2, "stroke-opacity": 1 } });
20
30
Something went wrong with that request. Please try again.