Skip to content

Instantly share code, notes, and snippets.

@3mcd
Last active January 6, 2016 14:16
Show Gist options
  • Save 3mcd/672ee11236027e469198 to your computer and use it in GitHub Desktop.
Save 3mcd/672ee11236027e469198 to your computer and use it in GitHub Desktop.
import { success, failure } from './assessment';
var results = [];
Tonic.createNotebook({
element: document.getElementById('embed'),
source: ``,
onResult: function (result) {
results.push(result);
},
onComplete: function () {
var correct = [];
var submitted = results.map(x => x.value.value);
var ui = success();
while (correct.push(correct.length) < 100);
if (results.length != 100)
ui = failure('Be sure to write a loop that does 100 iterations.');
if (!results.every(x => x.type == 'console.log'))
ui = failure('Be sure to use `console.log` and a loop to log out 0-99.');
for (var i = 0; i < results.length; i++) {
if (submitted[i] !== correct[i])
ui = failure(`Iteration #${i} failed.`);
}
return ui(this.element);
}
});
// or just generate an array behind the scenes
{
onComplete: function (results) {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment