diff --git a/index.js b/index.js index ea48454..be87f6e 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,7 @@ 'use strict' const gradefile = require('./grades.json') +const colors = require('colors'); console.log("Parsing grades file") @@ -37,7 +38,84 @@ secondYear.forEach(module => { secondParseInfo.totalCredits += module.credits }) -console.log(secondParseInfo) +// Should only be two 10 credit modules +if (secondParseInfo.noOf10 !== 2) { + console.log("\n⚠️ Second year should have two '10' credit modules! ⚠️\n".red) + process.exit(1) +} + +// Should only be 0 or 1 40 credit module +if (secondParseInfo.noOf40 > 1) { + console.log("\n⚠️ Second year can only have one '30' credit module! ⚠️\n".red) + process.exit(1) +} + +// Modules should either be 10, 20 or 40 +if (secondParseInfo.noOfOther > 0) { + console.log("\n⚠️ Second year modules should only have the credit amounts: '10', '20', and '40'! ⚠️\n".red) + process.exit(1) +} + +if (secondParseInfo.noOf40 > 0 && secondParseInfo.totalCredits !== 160) { + console.log("\n⚠️ Second year credits should add to '160' with a '40' credit module! ⚠️\n".red) + process.exit(1) +} else if (secondParseInfo.noOf40 === 0 && secondParseInfo.totalCredits !== 120) { + console.log("\n⚠️ Second year credits should add to '120' ('160' if you went on placement) ⚠️\n".red) + process.exit(1) +} + +console.log("Second year looks good 😄") + +const thirdParseInfo = { + noOf30: 0, + noOf20: 0, + noOf10: 0, + noOfOther: 0, + + totalCredits: 0 +} + +thirdYear.forEach(module => { + switch (module.credits) { + case 30: + thirdParseInfo.noOf30 += 1 + break + case 20: + thirdParseInfo.noOf20 += 1 + break + case 10: + thirdParseInfo.noOf10 += 1 + break + default: + thirdParseInfo.noOfOther += 1 + break + } + + thirdParseInfo.totalCredits += module.credits +}) + +if (thirdParseInfo.noOf10 !== 1) { + console.log("\n⚠️ Third year can only have one '10' credit module! ⚠️\n".red) + process.exit(1) +} + +if (thirdParseInfo.noOf30 > 1) { + console.log("\n⚠️ Third year can only have one '30' credit module! ⚠️\n".red) + process.exit(1) +} + +if (thirdParseInfo.noOfOther > 0) { + console.log("\n⚠️ Third year modules should only have the credit amounts: '10', '20', and '30'! ⚠️\n".red) + process.exit(1) +} + +if (thirdParseInfo.totalCredits !== 120) { + console.log("\n⚠️ Third year credits should add to '120' ⚠️\n".red) + process.exit(1) +} + +console.log("Third year looks good 😄") + // third year avg with lowest 20 missing // // third year avg without lowest missing