# Khan/khan-exercises

1 parent 535441a commit f161590fb130cd5eae9bdac244b6d27092742ea4 pappy74 committed
Showing with 22 additions and 3 deletions.
1. +2 −2 exercises/rate_problems_1.html
2. +20 −1 khan-exercise.js
4 exercises/rate_problems_1.html
 @@ -35,7 +35,7 @@

Alice traveled by VEHICLE1 at an average speed of SPEED1 miles per hour.

Then, she traveled by VEHICLE2 at an average speed of SPEED2 miles per hour.

-

In total, she traveled DIST miles for TIME hourTIME > 1 ? "s" : "".

+

In total, she traveled DIST miles for TIME hourplural(TIME).

How many miles did Alice travel by VEHICLE1? (Round to the nearest mile.)

round(DIST1)

@@ -78,4 +78,4 @@ - +
21 khan-exercise.js
 @@ -117,6 +117,25 @@ function initRandom() { jQuery.extend(KhanUtil, { random: function() { return m.random(); + }, + + // pluralization helper. There are three signatures + // - plural(NUMBER): return "s" if NUMBER is not 1 + // - plural(NUMBER, plural_suffix): return plural_suffix if NUMBER is + // not 1 + // - plural(NUMBER, singular, plural): return singular if NUMBER is 1, + // otherwise return plural + plural: function(value, arg1, arg2) { + var valIs1 = (value === 1); + if ( arg1 === undefined ) { + return valIs1 ? "" : "s"; + } + + if ( arg2 === undefined ) { + return valIs1 ? "" : arg1; + } + + return valIs1 ? arg1 : arg2; } }); } @@ -344,4 +363,4 @@ function queryString() { } return urlParams; -} +}