JavaScript Ali Express Discounted Cart

From Chorke Wiki
Revision as of 20:30, 13 November 2019 by Shahed (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
var AliExp=AliExp||(function(me){
    me.Cart     = {
        TotalUSD : 82.55,
        TotalMYR : 340.5,
        Print    : function(){
            me.CartPrice.Print();
            me.DiscPrice.Print();
            me.ExchPrice.Print();
        }
    };
    me.exchRate = (me.Cart.TotalMYR/me.Cart.TotalUSD);
    return me;
})({});
;AliExp.CartPrice||(function($, me){
    me = {
        Shahed   : {
            Total: (38.84 + 17.59 + 14.15 + 3.49 + 2.75)
        },
        Saikat   : {
            Total: (38.84)
        },
        Total    : function(total){
            total = me.Shahed.Total + me.Saikat.Total;
            return total;
        },
        Print    : function(msg){
            msg  = '\nBefore Discount:';
            msg += '\nShahed Total Amount: US $' + Math.floor(me.Shahed.Total*100)/100;
            msg += '\nSaikat Total Amount: US $' + Math.floor(me.Saikat.Total*100)/100;
            console.log(msg);
        }
    }
    $.CartPrice = me;
})(AliExp);
;AliExp.DiscPrice||(function($, me){
    me = {
        Total    : $.Cart.TotalUSD,
        Shahed   : {
            Total: function(total){
                total = $.CartPrice.Shahed.Total * (me.Total/$.CartPrice.Total());
                return total;
            }
        },
        Saikat   : {
            Total: function(total){
                total = $.CartPrice.Saikat.Total * (me.Total/$.CartPrice.Total());
                return total;
            }
        },
        Print    : function(msg){
            msg  = '\nAfter Discount:';
            msg += '\nShahed Total Amount: US $' + Math.floor(me.Shahed.Total()*100)/100;
            msg += '\nSaikat Total Amount: US $' + Math.floor(me.Saikat.Total()*100)/100;
            console.log(msg);
        }
    }
    $.DiscPrice = me;
})(AliExp);
;AliExp.ExchPrice||(function($, me){
    me = {
        Shahed   : {
            Total: function(total){
                total = $.DiscPrice.Shahed.Total() * $.exchRate;
                return total;
            }
        },
        Saikat   : {
            Total: function(total){
                total = $.DiscPrice.Saikat.Total() * $.exchRate;
                return total;
            }
        },
        Print    : function(msg){
            msg  = '\nDiscounted Exchange Price:';
            msg += '\nShahed Total Amount: MY ¥' + Math.floor(me.Shahed.Total()*100)/100;
            msg += '\nSaikat Total Amount: MY ¥' + Math.floor(me.Saikat.Total()*100)/100;
            console.log(msg);
        }
    }
    $.ExchPrice = me;
})(AliExp);
AliExp.Cart.Print();