# Khan/khan-exercises

Fix up number line problem

1 parent 1438922 commit 42b65ba883c7006bab1fdfa9678eeee92560c460 xymostech committed Jun 13, 2012
Showing with 20 additions and 16 deletions.
1. +20 −16 exercises/number_line.html
36 exercises/number_line.html
 @@ -15,24 +15,28 @@
-

Drag the orange dot to NUMBER. The distance between adjacent tick marks is 1.

+

Drag the orange dot to NUMBER. The distance between tick marks is 1.

init({ - range: [ [LOWER_BOUND - 1, UPPER_BOUND + 1], [-1, 1] ] + range: [[LOWER_BOUND - 1, UPPER_BOUND + 1], [-1, 1]] }); - line( [ LOWER_BOUND, 0 ], [ UPPER_BOUND, 0 ] ); - for ( var x = LOWER_BOUND; x <= UPPER_BOUND; x++ ) { - line( [ x, -0.2 ], [ x, 0.2 ] ); + line([LOWER_BOUND, 0], [UPPER_BOUND, 0]); + for (var x = LOWER_BOUND; x <= UPPER_BOUND; x++) { + line([x, -0.2], [x, 0.2]); } style({ stroke: "#6495ED", strokeWidth: 3.5 }); - line( [ 0, -0.2], [0, 0.2]); - label( [ 0, -0.53 ], "0", "center", { color: "#6495ED" }); + line([0, -0.2], [0, 0.2]); + label([0, -0.53], "0", "center", { color: "#6495ED" }); addMouseLayer(); - graph.movablePoint = addMovablePoint({ constraints: { constrainY: true }, snapX: 0.25 }); + graph.movablePoint = addMovablePoint({ constraints: { constrainY: true } }); graph.movablePoint.onMove = function( x, y ) { - return [ min( max( LOWER_BOUND, x ), UPPER_BOUND ), y ]; + var newx = round(x); + if (abs(newx - x) < 0.25) { + x = newx; + } + return [min(max(LOWER_BOUND, x), UPPER_BOUND), y]; };
@@ -41,13 +45,13 @@ Move the orange dot to select your answer.
graph.movablePoint.coord[0]
- if ( guess === 0 ) { + if (guess === 0) { return ""; } - return abs( NUMBER - guess ) < 0.001; + return abs(NUMBER - guess) < 0.001;
- graph.movablePoint.setCoord( [ guess, 0 ] ); + graph.movablePoint.setCoord([guess, 0]);
@@ -57,15 +61,15 @@
style({ stroke: "#6495ED", fill: "#6495ED", strokeWidth: 3.5, arrows: "->" }); - line( [ 0, 0 ], [ NUMBER, 0 ] ); + line([0, 0], [NUMBER, 0]); graph.movablePoint.visibleShape.toFront();
-

The orange dot should be plural( abs( NUMBER ), "position") to the leftright of 0.

+

The orange dot should be plural(abs(NUMBER), "tick mark") to the leftright of 0.

- label( [ NUMBER, -0.53 ], NUMBER, "center", { color: "#FFA500" }); - graph.movablePoint.moveTo( NUMBER, 0 ); + label([NUMBER, -0.53], NUMBER, "center", {color: "#FFA500"}); + graph.movablePoint.moveTo(NUMBER, 0);

The orange number shows where NUMBER is on the number line.