/*
8.3.2017 päivitetty pisteet vastaamaan 2016+ kursseja
*/
$(document).ready(function() {
var min = 1;
var count = 0;
var max = 32;
var random = 0;
var total = 0;
$('.nappi').click(function() {
checkOp(this.id);
});
$('.pisteet').hover(function() {
$(this).fadeTo(1000, 0.1, 'linear', function() {
var temp = parseInt($(this).text(), 10);
if (temp < 32) { // Hover gives ++ to points :)
$(this).html((temp + 1) + "/" + max);
total++;
} else { // Update total when max is changed to min
$(this).html(min + "/" + max);
total -= max - min;
}
showOp(count);
});
}, function() {
$(this).fadeTo(1000, 1, 'linear');
});
function checkOp(op) {
// Muuta siten että teoriaosuudet ei vaadi 4/8 kun useampia tentitty
if ($('#' + op + 'op').is(':hidden')) {
count += 1;
random = Math.floor(Math.random() * (max - min + 1)) + min;
total += random;
$('#' + op + 'p').html(random + "/" + max);
} else if (count > 0) {
count -= 1;
total -= parseInt($('#' + op + 'p').text(), 10);
}
$('#' + op + 'op').fadeToggle(1000, 'linear');
$('#' + op + 'pp').fadeToggle(1000, 'linear');
$('#' + op + 'p').fadeToggle(1000, 'linear');
showOp(count);
}
function showOp(count) {
$('#op1').html(count + " op");
$('#oppist').html(total + "/" + max * count);
$('#arvolause').html(laskeAS(total, count));
}
function laskeAS(total, op) {
if (op >= 0) {
a = total / op - 12.0;
if (a >= 18) return 5;
else if (a >= 14) return 4;
else if (a >= 10) return 3;
else if (a >= 6) return 2;
else if (a >= 4) return 1;
else return 0;
}
}
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.