Khan/khan-exercises

Switch branches/tags
Nothing to show
Fetching contributors…
Cannot retrieve contributors at this time
123 lines (111 sloc) 5.71 KB
 Place value
shuffle([1, 2, 3, 4, 5, 6, 7, 8, 9]).slice( 0, 4 ) digitsToInteger( DIGITS ) randRange( 0, 3 ) DIGITS[POWER] (function() { var maxPower = DIGITS.length - 1; var products = $.map( DIGITS, function( digit, index ){ return "(" + digit + "\\times" + pow(10, maxPower - index) + ")"; }); return products.join( "+" ); })() (function() { var maxPower = DIGITS.length - 1; var words =$.map( DIGITS, function( digit, index ) { var value = powerToPlace( maxPower - index ); return "<code>" + digit + "</code> " + KhanUtil.plural(value, digit); }); return words.join(" <code>+</code> "); })() (function() { var places = placesLeftOfDecimal.slice( 0, 4 ); return $.map( places, function( place, i ) { return place + "s"; }); })() PLACES[ DIGITS.length - 1 - POWER ] What is the place value of DIGIT in NUMBER? capitalize(SOLUTION) • capitalize(place) NUMBER can be represented as follows. = HINT_IN_NUMBERS = HINT_IN_WORDS Thus, DIGIT is in the SOLUTION place. randRange( 0, 9, 4 ) digitsToInteger( DIGITS ) [ ] (function() { var maxPower = DIGITS.length - 1; return$.map(DIGITS, function(digit, index) { if ( digit === 0 ) { return null; } var addend; if ( index === DIGITS.length - 1 ) { if ( DIGITS[ index - 1] === 0 ) { ADDENDS.push( digit ); return Cardinal( digit ) + " is the same as <code>" + digit + "</code>"; } } else if ( index === DIGITS.length - 2 ) { addend = digit * 10 + DIGITS[ DIGITS.length - 1 ]; ADDENDS.push( addend ); return Cardinal( addend ) + " is the same as <code>" + addend + "</code>"; } else { var words = Cardinal( digit ) + " " + powerToPlace(maxPower - index); var placeValue = pow(10, maxPower - index); ADDENDS.push( digit * placeValue); return words + " is the same as <code>" + digit + "\\times" + placeValue + " = " + (digit * placeValue) + "</code>"; } }); })()

Rewrite cardinal( NUMBER ) in numerals.

NUMBER

hint

Add all these parts up:

ADDENDS.join( " + " )

= NUMBER