(Created page with "switch (mw.config.get('wgPageTitle')) { case 'Randomizers': $(document).ready(function() { $("#calculatorDiv").empty(); $("#calculatorDiv").append('<input type=...") |
No edit summary |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
$(document).ready(function() { | |||
$("#calculatorDiv").empty(); | |||
$("#calculatorDiv").append('<input type="number" id="calculator"></input>'); | |||
$('#calculator').keyup(calculateSeason); | |||
$('#calculator').change(calculateSeason); | |||
}); | |||
function calculateSeason() { | |||
if ($(this).val().match(/^\d+$/)) { | |||
var season = 'Unknown'; | |||
var sleepTimes = parseInt($(this).val()); | |||
sleepTimes = (sleepTimes + 1) % 554400; | |||
var seasonNumber = Math.floor((sleepTimes + 4)/ 3) % 4; | |||
switch (seasonNumber){ | |||
case 0: | |||
season = 'Winter'; | |||
break; | |||
case 1: | |||
season = 'Spring'; | |||
break; | |||
case 2: | |||
season = 'Summer'; | |||
break; | |||
case 3: | |||
season = 'Fall'; | |||
break; | |||
} | |||
var limite = false; | |||
var i = 1; | |||
while (!limite) { | |||
sleepTimes++; | |||
seasonNumberTest = (Math.floor((sleepTimes + 4)/ 3)) % 4; | |||
if (seasonNumberTest == seasonNumber) i++; | |||
else limite = true; | |||
} | |||
$("#results").empty(); | |||
$("#results").append('The season in your next dream will be <b>' + season + '</b>. '); | |||
if (i == 1) { | |||
$("#results").append('This is the last day of the season.'); | |||
} | |||
else { | |||
$("#results").append('This season will last for ' + i + ' more days.'); | |||
} | |||
} | |||
else { | |||
$(this).val(''); | |||
$("#results").empty(); | |||
$("#results").append('Type a valid positive integer on the input field.'); | |||
} | |||
} | } |
Latest revision as of 06:40, 13 December 2022
$(document).ready(function() {
$("#calculatorDiv").empty();
$("#calculatorDiv").append('<input type="number" id="calculator"></input>');
$('#calculator').keyup(calculateSeason);
$('#calculator').change(calculateSeason);
});
function calculateSeason() {
if ($(this).val().match(/^\d+$/)) {
var season = 'Unknown';
var sleepTimes = parseInt($(this).val());
sleepTimes = (sleepTimes + 1) % 554400;
var seasonNumber = Math.floor((sleepTimes + 4)/ 3) % 4;
switch (seasonNumber){
case 0:
season = 'Winter';
break;
case 1:
season = 'Spring';
break;
case 2:
season = 'Summer';
break;
case 3:
season = 'Fall';
break;
}
var limite = false;
var i = 1;
while (!limite) {
sleepTimes++;
seasonNumberTest = (Math.floor((sleepTimes + 4)/ 3)) % 4;
if (seasonNumberTest == seasonNumber) i++;
else limite = true;
}
$("#results").empty();
$("#results").append('The season in your next dream will be <b>' + season + '</b>. ');
if (i == 1) {
$("#results").append('This is the last day of the season.');
}
else {
$("#results").append('This season will last for ' + i + ' more days.');
}
}
else {
$(this).val('');
$("#results").empty();
$("#results").append('Type a valid positive integer on the input field.');
}
}