Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var RollCalculator = function() {
  2.         this.pattern = "";
  3.     };
  4.  
  5.     RollCalculator.prototype = {
  6.         setStrategy: function(pattern) {
  7.             this.pattern = pattern;
  8.         },
  9.  
  10.         calculate: function(rolls) {
  11.             let wallWidth = document.getElementById("wallWidth").value;
  12.             let wallHeight = document.getElementById("wallHeight").value;
  13.             let rollWidth = document.getElementById("rollWidth").value / 100;
  14.             let rollLength = document.getElementById("rollLength").value;
  15.             let repeat = document.getElementById("repeat").value / 100;
  16.             return this.pattern.calculate(wallWidth, wallHeight, rollLength, rollWidth, repeat);
  17.         }
  18.     };
  19.  
  20.     var StraightMatch = function() {
  21.         this.calculate = function(wallWidth, wallHeight, rollLength, rollWidth, repeat) {
  22.             let drops = wallWidth / rollWidth;
  23.             let wastePerDrop = (repeat - (wallHeight % repeat));
  24.             let totalLengthPerDrop = parseFloat(wallHeight) + parseFloat(wastePerDrop);
  25.             let totalAddExtra = totalLengthPerDrop + (totalLengthPerDrop * (10 / 100));
  26.             let dropsPerRoll = Math.floor(rollLength / totalAddExtra);
  27.             let totalRolls = document.getElementById("rolls").value = drops / dropsPerRoll;
  28.             return document.getElementById("rollsRounded").value = Math.ceil(totalRolls);
  29.         }
  30.     };
  31.  
  32.     var log = (function() {
  33.         var log = "";
  34.  
  35.         return {
  36.             add: function(msg) {
  37.                 log += msg + "\n";
  38.             },
  39.             show: function() {
  40.                 alert(log);
  41.                 log = "";
  42.             }
  43.         }
  44.     })();
  45.  
  46.     function run() {
  47.         var straightMatch = new StraightMatch();
  48.  
  49.         var rollCalculator = new RollCalculator();
  50.  
  51.         rollCalculator.setStrategy(straightMatch);
  52.         log.add("Straight Match: " + rollCalculator.calculate());
  53.  
  54.         log.show();
  55.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement