Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function realEstateAgency () {
- let profit = $('h1').eq(0);
- let profitSum = 0;
- //let roof = $('#roof');
- let building = $('#building');
- let message = $('#message');
- let offers = [];
- let price = $('input[name=apartmentRent]');
- let apratment = $('input[name=apartmentType]');
- let commRate = $('input[name=agencyCommission]');
- let familyBudget = $('input[name=familyBudget]');
- let familyApartType = $('input[name=familyApartmentType]');
- let family = $('input[name=familyName]');
- let regOffer = $('button[name=regOffer]');
- regOffer.on('click', function() {
- let allPresent = price.val() !== undefined && apratment.val() !== undefined && commRate.val() !== undefined;
- let bothAreNums = typeof +price.val() === 'number' && typeof +commRate.val() === 'number'
- let validApartmentType = apratment.val() !== ' ' && !apratment.val().includes(':');
- if(allPresent && validApartmentType && +price.val() > 0 &&
- bothAreNums && +commRate.val() >= 0 && +commRate.val() <= 100 ) {
- let buildDiv = $('<div>').addClass('apartment');
- let p1 = $('<p>').text(`Rent: ${price.val()}`);
- let p2 = $('<p>').text(`Type: ${apratment.val()}`);
- let p3 = $('<p>').text(`Commission: ${commRate.val()}`);
- buildDiv.append(p1, p2, p3);
- building.append(buildDiv);
- message.text('Your offer was created successfully.');
- } else {
- message.text('Your offer registration went wrong, try again.');
- }
- price.val('');
- apratment.val('');
- commRate.val('');
- });
- let findOffer = $('button[name=findOffer]');
- findOffer.on('click', function() {
- let apps = $('div.apartment');
- let searched = familyApartType.val()
- let isIn = false;
- for (let app of apps) {
- let rentVal = $(app).find('p').eq(0).text().substring(6);
- let typeVal = $(app).find('p').eq(1).text().substring(6);
- let rateVal = $(app).find('p').eq(2).text().substring(12);
- let ratePercentVal = +rentVal + (+rentVal * (+rateVal / 100));
- let isBudgetEnough = ratePercentVal <= +familyBudget.val();
- if(searched === typeVal && isBudgetEnough) {
- isIn = true;
- }
- console.log(isIn)
- }
- let allPresent = familyBudget.val() !== undefined && familyApartType.val() !== undefined && family.val() !== undefined;
- if(allPresent && familyApartType.val() !== ' ' && family.val() !== ' ' && +familyBudget.val() > 0 && isIn) {
- for (let app of apps) {
- let rent = $(app).find('p').eq(0).text().substring(6);
- let type = $(app).find('p').eq(1).text().substring(6);
- let rate = $(app).find('p').eq(2).text().substring(12);
- let percent = +rent * (+rate / 100);
- let ratePercent = +rent + (+rent * (+rate / 100));
- let isBudgetEnough = ratePercent <= +familyBudget.val();
- if(type === familyApartType.val() && isBudgetEnough) {
- profitSum += percent * 2;
- profit.text(`Agency profit: ${profitSum} lv.`);
- $(app).find('p').eq(0).text(`${family.val()}`);
- $(app).find('p').eq(1).text('live here now');
- $(app).find('p').eq(2).remove();
- $(app).attr('style', "border: 2px solid red;");
- $(app).append($('<button>').text('MoveOut').on('click', function(ev) {
- let thisApp = ev.target.parentNode;
- console.log('inside MoveOut')
- message.text(`They had found cockroaches in ${$(thisApp).find('p').eq(0).text()}\'s apartment`);
- $(thisApp).remove();
- }))
- }
- }
- message.text('Enjoy your new home! :))');
- } else {
- message.text('We were unable to find you a home, so sorry :(');
- }
- familyBudget.val('');
- familyApartType.val('');
- family.val('');
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement