# Khan/khan-exercises

Fetching contributors…
Cannot retrieve contributors at this time
379 lines (342 sloc) 19.5 KB
 Graphing points
rand(3) === 0 ORIGIN ? [0, 0] : [randRange(0, 10), randRange(0, 10)]

Plot a point on the origin by clicking on the graph.

Plot (X, Y) by clicking on the graph.

graphInit({ range: [ [-1, 11], [-1, 11] ], scale: 30, axisArrows: "<->", tickStep: 1, labelStep: 1, gridOpacity: 0.05, axisOpacity: 0.2, tickOpacity: 0.4, labelOpacity: 0.5 }); //label( [ 0, 11 ], "y", "above" ); //label( [ 11, 0 ], "x", "right" ); graph.guess = [-1, -1]; graph.addPoint = function(coord) { if (graph.point) { graph.point.remove(); } var pos = _.map(coord, function(i) { return round(max(0, i) * 2) * 0.5; }) graph.point = circle(pos, 0.2, { fill: ORANGE, stroke: null }); graph.guess = pos; } addMouseLayer({ onClick: graph.addPoint }); graph.showCorrect = function() { graph.addPoint([X, Y]); };
Click on the graph to plot a point.
graph.guess
if (guess[0] === -1 && guess[1] === -1) { return "You need to click on the graph."; } return (guess[0] === X && guess[1] === Y);

The origin is at point (0, 0), where the x-axis and y-axis intersect.

Coordinates are listed as (\blue{x},\green{y}).

So, for ( \blue{X}, \green{Y} ) our x-coordinate is X and our y-coordinate is Y.

The x-coordinate tells how far we move to the right from the origin and the y-coordinate tells us how far we move up from the origin.

Since our x-coordinate is equal to 0, we don't need to move to the right of the origin.

Since our x-coordinate is equal to X, we move X to the right of the origin.

style({ stroke: BLUE, strokeWidth: 3, arrows: "->" }, function() { line( [ 0, 0 ], [ X, 0 ]); });
Since our y-coordinate is equal to 0, we don't need to move up from the origin.

Since our y-coordinate is equal to Y, we move up Y from the origin.

style({ stroke: GREEN, strokeWidth: 3, arrows: "->" }, function() { line( [ X, 0 ], [ X, Y ] ); }); if (graph.point) { graph.point.toFront(); }

Plot a point at (\blue{X}, \green{Y}), marked above.

style({ stroke: PINK, strokeWidth: 3 }, function() { line( [ X - 0.25, Y - 0.25 ], [ X + 0.25, Y + 0.25 ] ); line( [ X + 0.25, Y - 0.25 ], [ X - 0.25, Y + 0.25 ] ); }); if (graph.point) { graph.point.toFront(); }
shuffle([0, randRange(1, 10)]) Y === 0

Plot a point on the x-axis by clicking on the graph.

Plot a point on the y-axis by clicking on the graph.

Click on the graph to plot a point.
graph.guess
if (guess[0] === -1 && guess[1] === -1) { return "You need to click on the graph."; } return (X_AXIS && guess[1] === 0) || (!X_AXIS && guess[0] === 0);

The x-axis is the horizontal axis.

The x-axis includes all the points where y = 0.

style({ stroke: BLUE, strokeWidth: 3, arrows: "->" }, function() { line([-0.8, 0], [11, 0]); line([10.8, 0], [-1, 0]); });

The y-axis is the vertical axis.

The y-axis includes all the points where x = 0.

style({ stroke: BLUE, strokeWidth: 3, arrows: "->" }, function() { line([0, -0.8], [0, 11]); line([0, 10.8], [0, -1]); });

Plot a point to anywhere on the blue line.

randRange(0, 10) randRange(0, 10) randFromArray(["x", "y"]) COORD === "x" ? X : Y

What is the COORD-coordinate of the point plotted below?

graphInit({ range: [ [-1, 12], [-1, 12] ], gridRange: [ [-1, 11], [-1, 11] ], scale: 30, axisArrows: "<->", tickStep: 1, labelStep: 1, gridOpacity: 0.05, axisOpacity: 0.2, tickOpacity: 0.4, labelOpacity: 0.5 }); label( [ 0, 11 ], "y", "above" ); label( [ 11, 0 ], "x", "right" ); graph.point = circle([X, Y], 0.2, { fill: BLUE, stroke: null });

The x-coordinate tells how far we move to the right from the origin.

The point is X unit to the right of the origin.

The point is X units to the right of the origin.

style({ stroke: PINK, strokeWidth: 3, arrows: "->" }, function() { line([0, Y], [X, Y]); }); graph.point.toFront();

The y-coordinate tells how far we move up from the origin.

The point is Y unit up from the origin.

The point is Y units up from the origin.

style({ stroke: PINK, strokeWidth: 3, arrows: "->" }, function() { line([X, 0], [X, Y]); }); graph.point.toFront();

randRange(0, 10) randRange(0, 10)

What are the coordinates of the point plotted below?

(\ X , \ Y\ )

Coordinates are listed as (\pink{x},\green{y}).

The x-coordinate tells how far we move to the right from the origin and the y-coordinate tells us how far we move up from the origin.

Since the point is \pink{X} unit to the right of the origin, the x-coordinate is equal to \pink{X}.

Since the point is \pink{X} units to the right of the origin, the x-coordinate is equal to \pink{X}.

style({ stroke: PINK, strokeWidth: 3, arrows: "->" }, function() { line([0, Y], [X, Y]); }); graph.point.toFront();

Since the point is \green{Y} unit up from the origin, the y-coordinate is equal to \green{Y}.

Since the point is \green{Y} units up from the origin, the y-coordinate is equal to \green{Y}.

style({ stroke: GREEN, strokeWidth: 3, arrows: "->" }, function() { line([X,0], [X, Y]); }); graph.point.toFront();

So the coordinates are (\pink{X}, \green{Y}).