# Khan/khan-exercises

Older
100644 142 lines (126 sloc) 4.71 KB
 0196b21 added subtraction_decimals Cyrik authored May 27, 2011 1 2ace114 Small arithmetic housecleaning marcia authored Aug 8, 2011 2 0196b21 added subtraction_decimals Cyrik authored May 26, 2011 3 72418b8 Add meta charset to all HTML pages. jeresig authored Jul 28, 2011 4 07d95d3 spicyj authored Jul 22, 2011 5 Subtracting decimals 0196b21 added subtraction_decimals Cyrik authored May 26, 2011 6 7 8 9
566aa29 Add exercise -- subtracting decimals marcia authored Jul 14, 2011 10
11 randRange( 101, 999 ) 12 randRange( 101, 999 ) 13 randRange( 1, 3 ) 14 randRange( 1, 3 ) 15 A * ( B_DECIMAL > A_DECIMAL ? pow( 10, B_DECIMAL - A_DECIMAL ) : 1) 16 B * ( A_DECIMAL > B_DECIMAL ? pow( 10, A_DECIMAL - B_DECIMAL ) : 1) 17 digits( NEW_A ) 18 19 (function() { 20 var result = digits( NEW_A ); 2ace114 Small arithmetic housecleaning marcia authored Aug 8, 2011 21 for ( var i = 0; i < ( A_DECIMAL - B_DECIMAL ) || result.length < A_DECIMAL + 1; i++ ) { 566aa29 Add exercise -- subtracting decimals marcia authored Jul 15, 2011 22 result.push( 0 ); 23 } 24 return result; 25 })() 26 27 (function() { 28 var result = digits( NEW_B ); 2ace114 Small arithmetic housecleaning marcia authored Aug 8, 2011 29 for ( var i = 0; i < ( B_DECIMAL - A_DECIMAL ) || result.length < B_DECIMAL + 1; i++ ) { 566aa29 Add exercise -- subtracting decimals marcia authored Jul 15, 2011 30 result.push( 0 ); 31 } 32 return result; 33 })() 34 3 35 2 36 1 37 0 38 4 39 7 40 1.5 0196b21 added subtraction_decimals Cyrik authored May 26, 2011 41
42 43
44
2ace114 Small arithmetic housecleaning marcia authored Aug 8, 2011 45

\Huge{roundTo( A_DECIMAL, A * pow( 10, -A_DECIMAL ) ).toFixed( A_DECIMAL ) - roundTo( B_DECIMAL, B * pow( 10, -B_DECIMAL ) ).toFixed( B_DECIMAL ) = {?}}

566aa29 Add exercise -- subtracting decimals marcia authored Jul 15, 2011 46
A * pow( 10, -A_DECIMAL ) - B * pow( 10, - B_DECIMAL )
0196b21 added subtraction_decimals Cyrik authored May 26, 2011 47
48
49
2ace114 Small arithmetic housecleaning marcia authored Aug 8, 2011 50
51 init({ f2a9138 Expand arithmetic's graphie ranges to fit labels. marcia authored Aug 9, 2011 52 range: [ [ -2, 17 ], [ -0.5, 4 ] ], 2ace114 Small arithmetic housecleaning marcia authored Aug 8, 2011 53 scale: [30, 45] 54 }); 55 style({ 56 fill: "black" 57 }); 58 59 graph.highlights = []; 60 for ( var i = 0; i < A_DIGITS.length; i++ ) { 61 graph.highlights.unshift( [] ); 62 } 63 64 path( [ [ -0.5, 0.5 ], [ X_MAX + 0.5, 0.5 ] ]); 65 66 label( [ 0, 1 ] ,"\\huge{-\\vphantom{0}}" ); 67 68 var oldHighlights = graph.highlights[ 0 ]; 566aa29 Add exercise -- subtracting decimals marcia authored Jul 15, 2011 69 while( oldHighlights.length ) { 70 oldHighlights.shift().remove(); 71 } 72 X_MAX = X_MAX + ( B_DECIMAL - A_DECIMAL ) * (A_DECIMAL < B_DECIMAL ? 1 : -1); ed5a693 igorT authored Jul 28, 2011 73 path( [ [ -0.5, 0.5 ], [ X_MAX + 0.5, 0.5 ] ]); f2a9138 Expand arithmetic's graphie ranges to fit labels. marcia authored Aug 10, 2011 74 graph.highlights[0].push( label( [ X_SIDE, Y_SIDE ], "\\text{Make sure the decimals are lined up.}", "right" ) ); 566aa29 Add exercise -- subtracting decimals marcia authored Jul 15, 2011 75 drawDigits( A_DIGITS.slice( 0 ).reverse(), X_MAX - A_DIGITS.length + 1, Y_FIRST ); 76 drawDigits( B_DIGITS.slice( 0 ).reverse(), X_MAX - B_DIGITS.length + 1, Y_SECOND ); 77 for ( var i = 0; i < 3; i++ ){ 78 ellipse( [ X_MAX - max( A_DECIMAL, B_DECIMAL ) + 0.5, i - 0.2 ], [ 0.09, 0.06 ] ); 79 } 80
81
82 var index = index; 83 2ace114 Small arithmetic housecleaning marcia authored Aug 8, 2011 84 var oldHighlights = graph.highlights[ index ]; 566aa29 Add exercise -- subtracting decimals marcia authored Jul 15, 2011 85 while( oldHighlights.length ) { 86 oldHighlights.shift().remove(); 87 } 88 89 if ( index !== 0 ) { 2ace114 Small arithmetic housecleaning marcia authored Aug 8, 2011 90 oldHighlights = graph.highlights[ index - 1 ]; 566aa29 Add exercise -- subtracting decimals marcia authored Jul 15, 2011 91 while( oldHighlights.length ) { 92 oldHighlights.shift().remove(); 93 } 94 } 95 96 var value = A_DIGITS[ index ]; 97 var withinB = index < B_DIGITS.length; 98 var subtrahend = withinB ? B_DIGITS[ index ] : 0; 99 var subStr = ""; cf02179 Strip trailing whitespace spicyj authored Jun 1, 2011 100 566aa29 Add exercise -- subtracting decimals marcia authored Jul 15, 2011 101 if ( value < subtrahend ) { 2ace114 Small arithmetic housecleaning marcia authored Aug 8, 2011 102 borrow( index, A_DIGITS, X_MAX, Y_FIRST, Y_CARRY, graph.highlights ); 566aa29 Add exercise -- subtracting decimals marcia authored Jul 15, 2011 103 } else if ( A_DIGITS[ index ] === A_ORIG[ index ] ) { 2ace114 Small arithmetic housecleaning marcia authored Aug 8, 2011 104 graph.highlights[ index ].push( label( [ X_MAX - index, Y_FIRST ], 566aa29 Add exercise -- subtracting decimals marcia authored Jul 15, 2011 105 "\\Huge{\\color{#6495ED}{" + A_DIGITS[ index ] +"}}" ) ); 106 } else { 2ace114 Small arithmetic housecleaning marcia authored Aug 8, 2011 107 graph.highlights[ index ].push( label( [ X_MAX - index, Y_CARRY ], 566aa29 Add exercise -- subtracting decimals marcia authored Jul 15, 2011 108 "\\color{#6495ED}{" + A_DIGITS[ index ] + "}", "below" ) ); 109 } cf02179 Strip trailing whitespace spicyj authored Jun 2, 2011 110 566aa29 Add exercise -- subtracting decimals marcia authored Jul 15, 2011 111 if ( withinB ) { 2ace114 Small arithmetic housecleaning marcia authored Aug 8, 2011 112 graph.highlights[ index ].push( label( [ X_MAX - index, Y_SECOND ], 566aa29 Add exercise -- subtracting decimals marcia authored Jul 15, 2011 113 "\\Huge{\\color{#6495ED}{" + B_DIGITS[ index ] + "}}" ) ); 114 subStr = " - \\color{#6495ED}{" + subtrahend + "}"; 115 } 116 117 var diff = A_DIGITS[ index ] - subtrahend; 118 label( [ X_MAX - index, Y_DIFF ], "\\Huge{" + diff + "}" ); 119 120 2ace114 Small arithmetic housecleaning marcia authored Aug 8, 2011 121 graph.highlights[ index ].push( label( [ X_MAX - index, Y_DIFF ], "\\Huge{\\color{#28AE7B}{" + diff + "}}" ) ); 566aa29 Add exercise -- subtracting decimals marcia authored Jul 15, 2011 122 2ace114 Small arithmetic housecleaning marcia authored Aug 8, 2011 123 graph.highlights[ index ].push( label( [ X_SIDE, Y_SIDE ], "\\Large{" 566aa29 Add exercise -- subtracting decimals marcia authored Jul 15, 2011 124 + "\\color{#6495ED}{" + A_DIGITS[ index ] + "}" 125 + subStr 126 + " = " 127 + "\\color{#28AE7B}{" + diff + "}}", "right" ) ); 128 129
130
2ace114 Small arithmetic housecleaning marcia authored Aug 8, 2011 131 while( graph.highlights.length ) { 132 var column = graph.highlights.shift(); 566aa29 Add exercise -- subtracting decimals marcia authored Jul 15, 2011 133 while ( column.length ) { 134 column.shift().remove(); 135 } 136 } 137
0196b21 added subtraction_decimals Cyrik authored May 26, 2011 138
139
140 141
Something went wrong with that request. Please try again.