Path: blob/master/final-grade-calculator/main.js
574 views
/* main.js1* Functions and scripts specific to FGC page (rendering, handlers, etc)2* (C) 2019 Ryan Zhang. All Rights Reserved.3* Interested in anything on here? Contact me at https://ryan778.github.io/about-me/ and we can discuss.4*/56let globalData = {// Contains all information inputted, makes life easier7gradeType: 0, // 0=weighted, 1=unweighted8examType: 0, // 0=final, 1=test9unequalTests: 0, // whether tests are weighted equally or not10testPolicy: 0, // 0=none, 1=drop lowest, 2=make up difference, 3=make up half of difference11calcType: 0, // 0=see what you need, 1=already took test, 2=auto detect12currentGrade: -1,13currentGradePts: -1, // for unweighted14currentGradeTotalPts: -1, // also for unweighted15finalWorth: -1, // weight of final (weighted)16finalWorthPts: -1, // weight of final (unweighted)17targetGrade: -1,18finalGrade: -1,19equalTestWeight: 1, // 0=no (use totalTestScore), 1=yes (use totalTests)20testWorth: -1, // weight of test (or points)21testAvg: -1, // average grade across all tests22totalTests: -1,23testCatPts: -1,24testCatTotalPts: -1,25lowestTest: -1, // lowest test26curvePolicy: 0, // 0=none, 1=to highest test, 2=square root, 3=nth root27curveTo: -1, // highest score (assuming scores curve to this score)28curveStrength: -1 // for nth root curves29};3031let alertMessages = {32'weight': `<b>Grade Weighting</b><br>Most colleges and many high school classes use a <b>weighted</b> grading system so that different assignments have different "weights" (e.g. final, tests, and homework). If your grade has any kind of categories, then you have a weighted grading system. <br><br>Some classes give point values to assignments instead, usually with the final being worth a lot more than say, homework. If that's your case, then you have an <b>unweighted</b> grading system.`,33'examType': `<b>Exam Type</b><br>If your final has its own category (most common for weighted classes, default on RogerHub), select <b>Final</b>.<br>If you're taking a test/exam, select <b>Test/Exam</b>.<br>If you're taking a final but the final is counted as a test/exam (less common, but some classes do this), also select <b>Test/Exam</b>.<br>The difference between the two is that selecting "final" assumes your "final" exam goes into its own category, whereas "test/exam" assumes there's already other tests/exams in the category.`,34'calcTypes': `<b>Grade Calculation Types</b><br>First of all, there's two main categories for weighted calculations - tests and finals. A final is put <b>into its own category</b> for weighing, whereas a test is put <b>with other tests</b>. <br><br>If you already took the test/final, you'll need to select an option that begins with "<b>I took a...</b>". Otherwise, the calculator will tell you how much you need to get on the test/final in order to <b>maintain a specified grade</b>.`,35'equalTests': `<b>Equal Test Weights</b><br>If each test is worth the same number of points (e.g., 100 pts per test), then select "yes". If each test is put in as a different number of points (e.g., one test is worth 30 pts, another is 35 pts, etc.) then select "no".<br/><br/>Note that "Test/Exam" does not have to be used on tests; it can be used for any category where you already have tests/assignments. Simply select "no" and enter the point total of the category you want to use grade calculator on.`,36'legal': `<b>Legal</b><br/>© 2019 Ryan Zhang.<br/>core.js is written by me and is used for grade calculations. It's licensed under <a href='https://www.gnu.org/licenses/gpl-3.0.en.html' target='_blank'>GPLv3</a>.</br>Everything else unlicensed for the time being (albeit being open source); <a href='https://ryan778.github.io/about-me/'>contact me</a> if interested.`37}3839let testAdjInfo = [`Your lowest test grade will be completely removed.`, `If your grade on the final is better than your lowest test, it'll replace your lowest test grade.`, `You'll get half the difference (if applicable) between your lowest test grade and the final.`];4041let testReqInputs = ['finalWorth']; // required inputs tied to test adjustment and/or "test/exam" input requirements4243function validateInput(val, type){44//Returns object {st: number, val: number, msg: string}; status 0=success, 1=warn, 2=error45if(typeof val !== 'string'){return {st: 2, msg: `An error occured and it's not your fault (report this as a bug!) - Invalid Data Type (${typeof val})`}}46switch(type){47case 'grd': //Grade (Accepts percents and letters)48if(parseFloat(val).toString() === val || parseFloat(val).toString() === val.slice(0, val.length-1) && val.slice(-1) === '0'){49if(parseFloat(val) > 150){50return {st: 1, val: parseFloat(val), msg: 'This looks rather high. Is there a typo?'};51}52else if(parseFloat(val) < 15){53return {st: 1, val: parseFloat(val), msg: 'This looks rather low. Is there a typo?'};54}55return {st: 0, val: parseFloat(val)}56}57else if(convToGrade(val) !== -1){58return {st: 0, val: convToGrade(val), msg: `<span class='nt-hidden-ltGrd'></span>Using ${val.toUpperCase()} as ${convToGrade(val)}%`}59}60return {st: 2, msg: `Invalid input (is it a number/letter grade?)`}61case 'weight': //Weight value (ex: 20%)62if(parseFloat(val).toString() === val){63if(parseFloat(val) > 65){64return {st: 1, val: parseFloat(val), msg: 'This looks rather high. Is there a typo?'};65}66else if(parseFloat(val) < 5){67return {st: 1, val: parseFloat(val), msg: 'This looks rather low. Is there a typo?'};68}69return {st: 0, val: parseFloat(val)}70}71return {st: 2, msg: `Invalid input (is it a number?)`}72case 'num': // Numerical value (ex: 5)73if(parseInt(val).toString() === val){74if(parseInt(val) >= 50){75return {st: 1, val: parseInt(val), msg: 'This looks rather high. Is there a typo?'};76}77else if(parseFloat(val) < 1){78if(parseFloat(val) < 0){79return {st: 2, msg: `You need a non-negative integer here!`}80}81return {st: 1, val: parseInt(val), msg: 'This looks rather low. Is there a typo?'};82}83return {st: 0, val: parseInt(val)}84}85return {st: 2, msg: `Invalid input (is it a whole number?)`}86case 'pts': // Points87case 'ptsSingle': // Points88if(val.match(/^\d*\.?\d*$/)){89if(parseFloat(val) >= 4000 || (type==='ptsSingle' && parseFloat(val) > 400)){90return {st: 1, val: parseFloat(val), msg: 'This looks rather high. Is there a typo?'};91}92else if(parseFloat(val) <= 10){93return {st: 1, val: parseFloat(val), msg: 'This looks rather low. Is there a typo?'};94}95return {st: 0, val: parseFloat(val)}96}97return {st: 2, msg: `Invalid input (is it a decimal number?)`}98case 'sp:testAvg': //Special: Test Average - Treated as a number, but is weighted depending on the value entered99if(parseFloat(val).toString() === val || parseFloat(val).toString() === val.slice(0, val.length-1) && val.slice(-1) === '0'){100if(parseFloat(val) > 150){101return {st: 1, val: parseFloat(val), msg: 'This looks rather high. Is there a typo?'}102}103if(globalData.testWorth === -1){104$('#inp_testAvg').val('');105return {st: 2, msg: 'Please enter the test weight first!'}106}107if(parseFloat(val) >= 70 || parseFloat(val) > globalData.testWorth * 1.1){108//Use grade as is109return {st: 0, val: parseFloat(val), msg: `Using ${parseFloat(val)}% as overall test grade (${(parseFloat(val)*globalData.testWorth/100).toFixed(2)}% weighted)`}110}111else{112//Use grade as weighted to test percentage113return {st: 0, val: (10000*parseFloat(val)/globalData.testWorth)/100, msg: `Using ${parseFloat(val)}% weighted as ${(100*parseFloat(val)/globalData.testWorth).toFixed(2)}% overall`}114}115}116else if(convToGrade(val) !== -1){117return {st: 0, val: convToGrade(val), msg: `Using ${convToGrade(val)}% as overall test grade (${(parseFloat(val)*globalData.testWorth/100).toFixed(2)}% weighted)`}118}119return {st: 2, msg: `Invalid input (is it a number/letter grade?)`}120case 'root': // similar to case "num", but allows decimals - only used in "what is n" question121if(val.match(/^\d*\.?\d*$/)){122if(parseFloat(val) >= 5){123return {st: 1, val: parseFloat(val), msg: 'This looks rather high. Is there a typo?'};124}125else if(parseFloat(val) <= 1){126return {st: 1, val: parseFloat(val), msg: 'This looks rather low. Is there a typo?'};127}128return {st: 0, val: parseFloat(val)}129}130return {st: 2, msg: `Invalid input (is it a decimal number?)`}131default:132return {st: 2, msg: `An error occured and it's not your fault (report this as a bug!) - <type> inputted is invalid (${type})`}133}134}135136function setBorderClass(ele, color){137//Usage: Remove existing border color to an input field and replace it with another class (input "red", "org", "gr", -1, 0, 1, or 2)138if(color === 0){color = 'gr'}139else if(color === 1){color = 'org'}140else if(color === 2){color = 'red'}141$(ele).removeClass('red-b org-b gr-b');142if(color === -1){return;}143$(ele).addClass(color+'-b');144}145146/*function showErrorMsg(prop, msg){147//Usage: Show an error message148149}*/150151function setStatusText(eleIn, id, msg){152//id: -1=clear, 0=green, 1=orange, 2=red153//eleIn is the input box, and not the input-status box154//msg is optional155let ele = $(eleIn).parent().find('.input-status');156ele.removeClass('red org gr');157ele.children('span').html(msg);158if(!msg){ele.children('span').text('');}159switch(id){160case 2:161ele.addClass('red');162ele.children('i').text('error');163break;164case 1:165ele.addClass('org');166ele.children('i').text('warning');167break;168case 0:169ele.addClass('gr');170ele.children('i').text('check');171if(msg){$(eleIn).parent().find('.percSign').text('')}172else{$(eleIn).parent().find('.percSign').text('%')}173break;174default:175case -1:176$(eleIn).parent().find('.percSign').text('%')177ele.children('i').text('');178break;179}180}181182function calcTestMod(){183// Uses under {globalData}:184// equalTestWeight = 0: totalTestScore, testAvg, lowestTestGrade185// equalTestWeight = 1: testWorth, totalTests, testAvg, lowestTestGrade186}187188function detPlu(n){189// Returns "an" for 8X, returns "a" for any other number190if(n >= 80 && n < 90){191return 'an'192}193return 'a'194}195196function validateInputs(vars){197// Checks [array] and makes sure all elements in [array] are valid, returns an error otherwise198// Only works with input fields (ex. not select fields)199let valid = true;200let possibleTypo = false;201vars.forEach((ele => {202if(globalData[ele] === -1){203if(!$('#inp_'+ele).hasClass('red-b')){204setBorderClass('#inp_'+ele, 'red')205setStatusText('#inp_'+ele, 2, `This can't be empty.`);206}207valid = false;208}209else if ($('#inp_'+ele).hasClass('org-b')){210possibleTypo = true}211}));212if(possibleTypo && valid){return 2}213return valid;214}215216function getSubtitle(grade){217if (grade > 115){218return 'Unless your teacher gives that much extra credit, you may have to lower your expectations slightly.'}219else if (grade > 100){220return 'Maybe there\'s extra credit? Or you can lower your expectations slightly?'}221else if(grade >= 95){222return "Looks like it might be a bit challenging, but you got this!"}223else if(grade >= 90){224return "Don't worry too much, you'll do great!"}225else if(grade >= 80){226return "Looks like it shouldn't be too bad!"}227else if(grade >= 70){228return "Maybe study just a little bit...?"}229else if(grade >= 60) {230return globalData.testPolicy===2?"Looks like you'll have no trouble!":"Looks like you'll have no trouble reaching your goal!"}231else if(grade >= 0){232return globalData.testPolicy===2?"Well that seems pretty easy to do.":"Maybe you could raise your expectations a little?"}233else{234return "Looks like you don't even have to show up!"}235}236237function processCalculations(){238let postCurveGrade = 0;239$('.calcRes').hide();240$('.p-res').hide();241$('#res_moreInfo').hide();242$('#res_warn-grdAdj').hide();243$('#res-warn').hide();244if($('.nt-hidden-ltGrd').length > 0){ //Letter grade used somewhere245$('#res-warn-gr').show()}246else{247$('#res-warn-gr').hide()}248// let t = globalData.targetGrade, w = globalData.finalWorth, wp = globalData.finalWorthPts, c = globalData.currentGrade, cp = globalData.currentGradePts, ct = globalData.currentGradeTotalPts, f = globalData.finalGrade, r, vald;249let f = globalData.finalGrade, c = globalData.currentGrade, t = globalData.targetGrade;250if(globalData.gradeType){251c = 100 * globalData.currentGradePts / globalData.currentGradeTotalPts}252/* if(globalData.gradeType === 1){253if(!validateInputs(['currentGradePts', 'currentGradeTotalPts', 'targetGrade', 'finalWorthPts'])){254$('#calcErr').show();255return}256let out = calcTargetGrade(t);257r = out[0];258$('#res-0').show();259$('#res-an-0').text(detPlu(r));260$('#res-val-0').text(`${r.toFixed(2)}% (${convToLetter(r)})`);261postCurveGrade = r;262$('#res-an-0b').text(detPlu(t));263$('#res-val-0b').text(`${t.toFixed(2)}% (${convToLetter(t)})`);264} */265if(globalData.testPolicy > 0){266if(globalData.testPolicy === 1){267$('#resi').show();268$('#resi_a').show()}269else{270$('#resi_b').show()}271if(globalData.testPolicy !== 2){272$('#res_moreInfo').show()}273}274switch(globalData.calcType){275case 0:276//targetGrade = (finalWorth/100)*whatYouNeed + currentGrade*(1-(finalWorth/100))277//whatYouNeed = (targetGrade - currentGrade*(1-(finalWorth/100))) / (finalWorth/100)278vald = globalData.gradeType?validateInputs(['currentGradePts', 'currentGradeTotalPts', 'targetGrade', 'finalWorthPts']):validateInputs(['targetGrade', 'currentGrade'].concat(testReqInputs));279if(!vald){280$('#calcErr').show();281return}282r = calcTargetGrade(t);283//r = (t-c*(1-(w/100)))/(w/100); //Algebraic manipulation284handleQueryAction(1, Math.round(c*100));285$('#res-0').show();286$('#res-an-0').text(detPlu(r));287$('#res-val-0').text(`${r.toFixed(2)}% (${convToLetter(r)})`);288postCurveGrade = r;289$('#res-an-0b').text(detPlu(t));290$('#res-val-0b').text(`${t.toFixed(2)}% (${convToLetter(t)})`);291// $('#res_sub').text(getSubtitle(Math.floor(r)));292if(vald === 2){$('#res-warn').show()}293break;294case 1:295//finalGrade = (finalWorth/100)*finalExamGrade + currentGrade*(1-(finalWorth/100))296vald = globalData.gradeType?validateInputs(['currentGradePts', 'currentGradeTotalPts', 'finalGrade', 'finalWorthPts']):validateInputs(['finalGrade', 'currentGrade'].concat(testReqInputs));297if(!vald){298$('#calcErr').show();299return}300r = calcResultingGrade(f);301if(globalData.testPolicy > 0 && !globalData.gradeType){ // test adjustment policies don't exist for unweighted classes302let endDiff = 0;303switch(globalData.testPolicy){304case 1:305endDiff = calcTestDrop()[1] - calcTestDrop()[0];306break;307case 2:308endDiff = ((globalData.testWorth/100)*(globalData.finalGrade - globalData.lowestTest)/globalData.totalTests);309break;310case 3:311endDiff = ((globalData.testWorth/100)*0.5*(globalData.finalGrade - globalData.lowestTest)/globalData.totalTests);312break;313}314if (endDiff > 0) {315r += endDiff;316$('#res-finalGrade-testAdj').find('b').text(endDiff.toFixed(2));317$('#res-finalGrade-testAdj').show()}318else{319$('#res-finalGrade-noTestAdj').show()}320};321handleQueryAction(2, Math.round(c*100));322$('#res-1').show();323$('#res-an-1').text(detPlu(r));324$('#res-val-1').text(`${r.toFixed(2)}% (${convToLetter(r)})`);325break;326case 2:327//whatYouNeed same as case 0, except used multiple times for various targetGrade to find the best one328vald = globalData.gradeType?validateInputs(['currentGradePts', 'currentGradeTotalPts', 'finalWorthPts']):validateInputs(['currentGrade'].concat(testReqInputs));329if(!vald){330$('#calcErr').show();331return}332handleQueryAction(3, Math.round(c*100));333let upper = Math.ceil(c/10)*10, lower = Math.floor(c/10)*10;334let r1 = calcTargetGrade(upper);335let r2 = calcTargetGrade(lower);336//let r1 = (upper-c*(1-(w/100)))/(w/100); //Upper target337//let r2 = (lower-c*(1-(w/100)))/(w/100); //Lower target338// let r3 = globalData.gradeType ? ((cp + wp) / (ct + wp) * 100) : ((w) + (c*(1-(w/100)))); //Final grade w/ 100%339let r3 = calcResultingGrade(100);340if(upper == 100 || r1 > 100){ //Show info to keep current grade (if upper is not achievable or grade is already an A)341calcTargetGrade(upper); //Calling this updates [More Info] section if necessary342$('#res-0').show();343$('#res-an-0').text(detPlu(r2));344$('#res-val-0').text(`${r2.toFixed(2)}% (${convToLetter(r2)})`);345$('#res-an-0b').text(detPlu(lower));346$('#res-val-0b').text(`${lower.toFixed(2)}% (${convToLetter(lower)})`);347postCurveGrade = r2;348// $('#res_sub').text(getSubtitle(Math.floor(r2)));349}350if(r1 > 100){ //Upper grade is not achievable351$('#res-1s').show();352$('#res-an-1s').text(detPlu(r3));353$('#res-val-1s').text(`${r3.toFixed(2)}% (${convToLetter(r3)})`);354calcTargetGrade(lower);355postCurveGrade = r2;356if (lower < 90 && (r3 % 10 > 7)) {$('#res_sub').text('Maybe you can get extra credit somewhere to bump it up?')} //Hide message if the lower bound is already an A or if there's a large gap (>3%) until the next letter grade357}358else{ //Upper grade is achievable359calcTargetGrade(upper); //Calling this updates [More Info] section if necessary360$('#res-0').show();361$('#res-an-0').text(detPlu(r1));362$('#res-val-0').text(`${r1.toFixed(2)}% (${convToLetter(r1)})`);363$('#res-an-0b').text(detPlu(upper));364$('#res-val-0b').text(`${upper.toFixed(2)}% (${convToLetter(upper)})`);365$('#res-0s').show();366$('#res-an-0s').text(detPlu(r2));367$('#res-val-0s').text(`${r2.toFixed(2)}% (${convToLetter(r2)})`);368postCurveGrade = r1;369// $('#res_sub').text(getSubtitle(Math.floor(r1)));370}371break;372default:373alert(`An error occured. \nPlease report this bug!\nError: invalid calcType (${globalData.calcType})`)374}375if(globalData.curvePolicy){ // curving the output grade if selected376$('.res-hasCurve').show();377let g = postCurveGrade;378if(globalData.curvePolicy >= 2){379if(globalData.curvePolicy == 3){380if(!validateInputs(['curveStrength'])){381$('#calcErr').show();382return}383}384let curveStrength = (globalData.curvePolicy==2)?2:globalData.curveStrength;385g = Math.pow(g/100, curveStrength)*100;386}387else{ // curvePolicy = 1388if(!validateInputs(['curveTo'])){389$('#calcErr').show();390return}391g = g * (globalData.curveTo/100);392}393$('#res-val-c').html(`${detPlu(g)} <b>${g.toFixed(2)}% (${convToLetter(g)})</b>`);394if(globalData.gradeType === 1){395$('#sp-pts-curve').show();396$('#res-val-curvePts').text(`${(g*globalData.finalWorthPts/100).toFixed(1)}/${globalData.finalWorthPts.toFixed(1)} pts`)397}398$('#res_sub').text(getSubtitle(Math.floor(g)));399}400else{401$('.res-hasCurve').hide();402$('#res_sub').text(getSubtitle(Math.floor(postCurveGrade)));403}404$('#calcRes').show();405}406407function registerHandlers(){408$('#calc').find('button').each((n, ele) => {409if($(ele).hasClass('btn-opt')){410$(ele).click(() => {411$('.'+ele.classList[1]).prop('disabled', false);412globalData[$(ele).data('for')] = $(ele).data('val');413$(ele).prop('disabled', true);414if($(ele).data('for') === 'examType' || $(ele).data('for') === 'unequalTests'){415updateTestInputs()}416else if($(ele).data('for') === 'gradeType'){417if($(ele).data('val') === 1){418$('.btn-opt.btn-opt-1')[0].click();419$('#sel_testAdj').val(0);420$('#sel_testAdj').change();421$('.p_weightedOnly').hide();422$('.p_unweightedOnly').show();423$('#opt_finalOrTest').hide();424$('.opt_testAdj').hide()425}426else{427$('.p_weightedOnly').show();428$('.p_unweightedOnly').hide();429$('.opt_testAdj').show();430$('#opt_finalOrTest').show();431}432}433});434}435else if(ele.id === 'calcBtn'){436$(ele).click(() => {437processCalculations();438if(window.innerWidth < 720) {439zenscroll.to(calcBtn, 500);440}441});442}443});444$('#calc').find('input').each((n, ele) => {445if($(ele).data('vald') === 'grd'){446ele.inputMode='decimal';447ele.maxLength = 6}448else if($(ele).data('vald') === 'weight'){ele.maxLength = 6}449else if($(ele).data('vald') === 'root'){ele.maxLength = 5}450else if($(ele).data('vald') === 'pts'){$(ele).css('width', '52px')}451$(ele).prop('id', 'inp_'+ele.dataset.for);452$(ele).change(() => {453let val = ele.value;454if(val === '' || val === ' '){455setBorderClass(ele, -1);456setStatusText(ele, -1, '');457globalData[$(ele).data('for')] = -1;458if(ele.dataset.for === 'testWorth'){459if($('#inp_testAvg').val() !== ''){460$('#inp_testAvg').change();461}462}463return}464let vald = validateInput(val, ele.dataset.vald);465setBorderClass(ele, vald.st);466setStatusText(ele, vald.st, vald.msg);467if(vald.st !== 2){//Input is valid468globalData[$(ele).data('for')] = vald.val469if(ele.dataset.for === 'testWorth'){470if($('#inp_testAvg').val() !== ''){471$('#inp_testAvg').change();472}473}474}475});476$(ele).on('input', () => {477if($(ele).hasClass('red-b')){478setBorderClass(ele, -1);479setStatusText(ele, -1);480}481})482});483$('#calc').find('select').each((n, ele) => {484$(ele).change(() => {485$('#calcRes').hide();486let val = ele.value;487if(!isNaN(parseInt(val))){val = parseInt(val)}488globalData[$(ele).data('for')] = val;489if(ele.dataset.for==='calcType'){490$('#info_opt2').hide();491let fg = (globalData.gradeType === 1?'#opt_finalWorthPts':'#opt_finalWorth');492$('#opt_targetGrade').hide();493$('#opt_finalGrade').hide();494$('.p_curve').show();495$(fg).show();496switch(ele.value){497case '0':498default:499$('#opt_targetGrade').show();500break;501case '1':502$('#opt_finalGrade').show();503$('#sel_curve').val(0);504$('#sel_curve').change();505$('.p_curve').hide();506break;507case '2':508$('#info_opt2').show()509break;510}511}512else if(ele.dataset.for==='testPolicy'){513updateTestInputs();514}515else if(ele.dataset.for='curvePolicy'){516$('#opt_curveTo').hide();517$('#opt_curveStrength').hide();518if(ele.value === '1'){519$('#opt_curveTo').show()}520else if(ele.value === '3'){521$('#opt_curveStrength').show()}522}523setBorderClass(ele, 'gr');524setTimeout(function(){525setBorderClass(ele, -1);526}, 1000);527});528});529$('html').find('.infoLink').each((n, ele) => {530$(ele).click(() => {531alertify.alert(alertMessages[ele.dataset.alertmsg])532});533});534$('#res_moreInfo').click(() => {535if(!$('#calcRes_moreInfo').is(':visible')){536$('#calcRes_moreInfo').show();537}538else{539$('#calcRes_moreInfo').hide();540}541});542}543544function updateTestInputs(){545testReqInputs = [];546547if(globalData.examType === 1){548$('.opt_testAdj').hide();549if(globalData.testPolicy){ // test policies don't work550$('#sel_testAdj').val(0);551$('#sel_testAdj').change();552return;553}554$('#opt_unequalTests').show()}555else{556$('.opt_testAdj').show();557$('#opt_unequalTests').hide()}558559if(globalData.unequalTests){560$('.p_testAdjUnequal').show();561$('.p_testAdjEqual').hide();562testReqInputs = ['testWorth', 'testCatPts', 'testCatTotalPts', 'testWorthPts'];563return;564}565else{566$('.p_testAdjUnequal').hide();567$('.p_testAdjEqual').show();568}569570if(globalData.examType === 0 && globalData.testPolicy === 0){ // neither "test" type nor test policy571$('.p_testAdj').hide();572$('#opt_finalWorth').show();573testReqInputs.push('finalWorth');574return;575}576$('.p_testAdj').show(); //All fields can be used for everything577testReqInputs.push('testWorth');578testReqInputs.push('totalTests');579if(globalData.testPolicy){ // test policy exists580$('#p_testAdjInfo').show();581$('#opt_lowestTest').show();582$('#sp_testAdjInfo').text(testAdjInfo[parseInt(globalData.testPolicy)-1]);583testReqInputs.push('lowestTest');584} else{585$('#p_testAdjInfo').hide();586$('#opt_lowestTest').hide();587}588if(globalData.examType == 1){589$('#opt_finalWorth').hide()}590else {591testReqInputs.push('finalWorth');592$('#opt_finalWorth').show()}593if(globalData.testPolicy !== 1 && globalData.examType == 0){594$('#p_testAvgInfo').hide();595$('#opt_testAvg').hide()}596else{597testReqInputs.push('testAvg');598$('#p_testAvgInfo').show();599$('#opt_testAvg').show()}600}601602$(document).ready(function () {603'use strict';604let h = location.hostname;605if(['127.0.0.1', '10.10.7.38', 'itsryan.org', 'ryan778.github.io', 'ryan778.herokuapp.com', 'ryan778.azurewebsites.net'].indexOf(h) === -1){606$('#calc-load').html(`<i class='material-icons'>error</i> <b>Non-Whitelisted Domain</b><br>It looks like you're opening this page somewhere it's not supposed to be.<br>Make sure that you're on <a href='https://ryan778.github.io/final-grade-calculator/'>the official website</a>, and if this error persists, <a href='https://bit.ly/fgc-feedback'>contact us here</a>.`);607return;608}609registerHandlers();610$('.p_testAdj').hide();611$('#opt_curveTo').hide();612$('#opt_unequalTests').hide();613$('.p_unweightedOnly').hide();614$('.p_testAdjUnequal').hide();615$('#opt_curveStrength').hide();616$('#calc-load').hide();617$('#calc-inner').show();618});619620