Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var RollCalculator = function() {
- this.pattern = "";
- };
- RollCalculator.prototype = {
- setStrategy: function(pattern) {
- this.pattern = pattern;
- },
- calculate: function(rolls) {
- let wallWidth = document.getElementById("wallWidth").value;
- let wallHeight = document.getElementById("wallHeight").value;
- let rollWidth = document.getElementById("rollWidth").value / 100;
- let rollLength = document.getElementById("rollLength").value;
- let repeat = document.getElementById("repeat").value / 100;
- return this.pattern.calculate(wallWidth, wallHeight, rollLength, rollWidth, repeat);
- }
- };
- var StraightMatch = function() {
- this.calculate = function(wallWidth, wallHeight, rollLength, rollWidth, repeat) {
- let drops = wallWidth / rollWidth;
- let wastePerDrop = (repeat - (wallHeight % repeat));
- let totalLengthPerDrop = parseFloat(wallHeight) + parseFloat(wastePerDrop);
- let totalAddExtra = totalLengthPerDrop + (totalLengthPerDrop * (10 / 100));
- let dropsPerRoll = Math.floor(rollLength / totalAddExtra);
- let totalRolls = document.getElementById("rolls").value = drops / dropsPerRoll;
- return document.getElementById("rollsRounded").value = Math.ceil(totalRolls);
- }
- };
- var log = (function() {
- var log = "";
- return {
- add: function(msg) {
- log += msg + "\n";
- },
- show: function() {
- alert(log);
- log = "";
- }
- }
- })();
- function run() {
- var straightMatch = new StraightMatch();
- var rollCalculator = new RollCalculator();
- rollCalculator.setStrategy(straightMatch);
- log.add("Straight Match: " + rollCalculator.calculate());
- log.show();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement