Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Added string.prototype + shippingDiscount
//DO NOT USE FRAMEWORKS
/**
* 1. Below discount rule should have dynamic data
* - Create a function to fill this dynamic data
* - Append to a HTML element with class .container
*/
/**
* 2. Expand above code to have unlimited amount of dynamic arguments
* - Use a regular expression to replace the dynamic arguments
* - Append to a HTML element with class .container
*/
/**
* 3. Create a prototype public function for above function
* - Use below String.prototype example
* - Define function and execute function, append result to a HTML element with class .container
*/
/**
* 4. Above code should be executed after every AJAX call
* - Create an EventListener and apply the event listener on the correct element
* - When the event is executed, execute the correct function
* - Show how the event should be triggered
*/
String.prototype.discountFunction = function () {
(function () {
'use strict';
var container = document.createElement('div');
var items = ['two', 'four', 'six', 'eight', 'ten'];
var discount = ['five', 'ten', 'fifteen', 'twenty', 'twentyfive'];
var shippingDiscount = ['ten', 'fifteen', 'twenty', 'twentyfive', 'thirty'];
container.className = 'container';
container.innerHTML = 'Add ' + items[0] + ' products and receive ' + discount[0] + ' euro discount and ' + shippingDiscount[0] + ' euro shipping discount!';
document.getElementById('section').appendChild(container);
})();
}
"discount".discountFunction();
@jefsnare

This comment has been minimized.

Copy link

commented Feb 16, 2017

Zo, daar komt de feedback dan eindelijk 😄

Regel 29: Kun je uitleggen waarom je 'use strict' defineert?
Regel 30: Hier creëer je de container, je gebruikt deze verder op in de code pas. Los van het feit dat de opdracht niet helemaal omschrijft dat je dit hoeft te doen. Er staat enkel 'Append to a HTML element with class .container'.

Ik zou graag zien dat je de functie refactored zodat je parameters aan de discountFunction kan meegeven. Wat ik verwacht en de opdracht redelijk abstract beschrijft is dat je het volgende gebruikt;
"Voeg nog {0} euro toe om {1} extra korting te krijgen".discountFunction(7, 25);

@mvhoute

This comment has been minimized.

Copy link
Owner Author

commented Feb 17, 2017

@jefsnare Ik gebruik 'use strict' om ervoor te zorgen dat mijn code valide is, en dus geen rare fouten bevat.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.