Commit a487016a authored by Kevin Lyda's avatar Kevin Lyda 💬
Browse files

Tweaked how numbers are generated.

parent 283b0bee
......@@ -23,12 +23,39 @@ var cube = document.getElementById("cube");
var cuberoot = document.getElementById("cuberoot");
var result = document.getElementById("result");
var stats = document.getElementById("stats");
var began;
var finished;
var elapsed = 0;
var generated;
var guesses = 0;
var correct = 0;
var began, finished, generated;
var elapsed = 0, guesses = 0, correct = 0;
var generator = [];
Array.prototype.shuffle = function () {
var i = this.length, val, j;
if (i > 2) {
while (i > 0) {
j = Math.floor(Math.random() * i);
i--;
if (i != j) {
val = this[i];
this[i] = this[j];
this[j] = val;
}
}
}
return this;
}
Array.prototype.random = function() {
if (this.length == 0) {
for (var i = 10; i < 100; i++) {
this.push(i);
if (i % 10 > 0) {
this.push(i);
}
}
this.shuffle();
}
return this.shift();
}
cuberoot.addEventListener("keydown", function (e) {
if (e.keyCode === 13) {
......@@ -46,14 +73,14 @@ function humanize_ms(ms) {
function start_round() {
if (guesses > 0) {
stats.innerHTML = "Got " + correct + " correct out of " + guesses +
stats.innerHTML = "Got " + correct + " out of " + guesses +
". Last round took " + humanize_ms(finished - began) +
"." + ((correct > 0)
?" Average time of correct guess was " +
?" Avg time of correct guesses was " +
humanize_ms(elapsed / correct) + "."
:"");
}
generated = Math.floor(Math.random() * 90) + 10;
generated = generator.random();
cube.innerHTML = "&nbsp;" + Math.pow(generated, 3) + "&nbsp;";
began = Date.now();
cuberoot.value = "";
......@@ -70,7 +97,9 @@ function check_cuberoot(e) {
elapsed += (finished - began);
result.innerHTML = "Correct!";
} else {
result.innerHTML = 'Not correct! <span style="white-space:nowrap;">' +
generator.push(generated, generated);
generator.shuffle();
result.innerHTML = 'Incorrect! <span style="white-space:nowrap;">' +
'<span style="font-size:larger;">&#8731;</span>' +
'<span style="text-decoration:overline;">&nbsp;' +
Math.pow(generated, 3) +
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment