Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 87 lines (83 sloc) 3.144 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
<!DOCTYPE html>
<html data-require="math expressions">
<head>
<meta charset="UTF-8" />
<title>Expressions with unknown variables 2</title>
<script src="../khan-exercise.js"></script>
</head>
<body>
<div class="exercise">
<div class="vars">
<var id="NUM_EXPRESSIONS">randRange( 1, 2 )</var>
<var id="NUM_TERMS">randRange( 2, 3, NUM_EXPRESSIONS )</var>
<var id="COEFFICIENTS">[ randRange( 1, 9, 3 ), randRange( 1, 9, 3 ) ]</var>
<var id="GROUPS">
(function() {
var variables = [ [ "a", "b", "c" ], [ "x", "y", "z" ] ];
var group = [];
for ( var i = 0; i &lt; NUM_EXPRESSIONS; i++ ) {
group.push( variables.shift().slice( 0, NUM_TERMS[ i ] ) );
}
return group;
})()
</var>

<var id="VALUES">[ randRangeNonZero( -10, 10 ), randRangeNonZero( -10, 10 ) ]</var>
<var id="FACTORS">[ randRangeNonZero( -10, 10 ), randRangeNonZero( -10, 10 ) ]</var>
<var id="ORIGINAL_EXPRESSIONS">
(function() {
var originals = [];
jQuery.each( GROUPS, function( index, group ) {
var coeffs = COEFFICIENTS[ index ];
var o = [];
jQuery.each( group, function( i, variable ) {
o.push( expr( [ "*", coeffs[ i ], variable] ) );
});
originals.push( o );
});
return originals;
})()
</var>
<var id="MULTIPLIED_EXPRESSIONS">
(function() {
var expression = [];
jQuery.each( GROUPS, function( index, group ) {
var coeffs = COEFFICIENTS[ index ];
jQuery.each( group, function( i, variable ) {
expression.push( expr( [ "*", (coeffs[ i ] * FACTORS[ index ] ), variable ] ) );
});
});
return expression;
})()
</var>
<var id="QUESTION">shuffle( MULTIPLIED_EXPRESSIONS ).join( " + " )</var>

<var id="ANSWER">
(function() {
var answer = 0;
for ( var i = 0; i &lt; NUM_EXPRESSIONS; i++ ) {
answer += ( FACTORS[ i ] * VALUES[ i ] );
}
return answer;
})()
</var>
</div>

<div class="problems">
<div>
<div class="question">
<p>If <code><var>ORIGINAL_EXPRESSIONS[ 0 ].join( " + " )</var> = <var>VALUES[ 0 ]</var></code> <span data-if="NUM_EXPRESSIONS === 2">and <code><var>ORIGINAL_EXPRESSIONS[ 1 ].join( " + " )</var> = <var>VALUES[ 1 ]</var></code></span>,</p>
<p>what is <code><var>QUESTION</var></code>?</p>
</div>
<p class="solution"><var>ANSWER</var></p>
</div>
</div>

<div class="hints">
<p><code>= <var>MULTIPLIED_EXPRESSIONS.join( " + " )</var></code></p>
<p><code>= (<var>FACTORS[ 0 ]</var>) \cdot (<var>ORIGINAL_EXPRESSIONS[ 0 ].join( " + " )</var>)
<span data-if="NUM_EXPRESSIONS === 2"> + (<var>FACTORS[ 1 ] </var>) \cdot (<var>ORIGINAL_EXPRESSIONS[ 1 ].join( " + " )</var>)</span></code></p>
<p><code>= (<var>FACTORS[ 0 ]</var>) \cdot (<var> VALUES[ 0 ]</var>)
<span data-if="NUM_EXPRESSIONS === 2"> + (<var>FACTORS[ 1 ]</var>) \cdot (<var> VALUES[ 1 ]</var>)</span></code></p>
<p data-if="NUM_EXPRESSIONS === 2"><code>= <var>FACTORS[ 0 ] * VALUES[ 0 ]</var> + <var>FACTORS[ 1 ] * VALUES[ 1 ]</var></code></p>
<p><code>= <var>ANSWER</var></code>
</div>
</div>
</body>
</html>
Something went wrong with that request. Please try again.