Advertisement
bebo231312312321

Untitled

Jun 15th, 2023
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. function solve() {
  3.   const makeInput = document.getElementById('make');
  4.   const modelInput = document.getElementById('model');
  5.   const productionInput = document.getElementById('year');
  6.   const fuelType = document.getElementById('fuel');
  7.   const originPrice = document.getElementById('original-cost');
  8.   const sellPrice = document.getElementById('selling-price');
  9.   const ulCarsList = document.getElementById('cars-list');
  10.   const profit = document.getElementById('profit');
  11.   const publishBtn = document.getElementById('publish');
  12.   const tbody = document.getElementById('table-body');
  13.  
  14.   publishBtn.addEventListener('click', onPublish)
  15.  
  16.   function onPublish(e) {
  17.     e.preventDefault();
  18.  
  19.     let make = makeInput.value
  20.     let model = modelInput.value
  21.     let product = Number(productionInput.value)
  22.     let fuel = fuelType.value
  23.     let oPrice = Number(originPrice.value);
  24.     let sPrice = Number(sellPrice.value)
  25.  
  26.     if (sPrice <= oPrice || !make || !model || !product || !fuel)  return;
  27.  
  28.     let publish = onCreate(make, model, product, fuel, oPrice, sPrice)
  29.     tbody.appendChild(publish)
  30.  
  31.     makeInput.value = "";
  32.     modelInput.value = "";
  33.     productionInput.value = "";
  34.     fuelType.value = "";
  35.     originPrice.value = "";
  36.     sellPrice.value = "";
  37.  
  38.   }
  39.   function onCreate(make, model, product, fuel, oPrice, sPrice) {
  40.  
  41.     const trElement = document.createElement('tr');
  42.     trElement.classList.add('row');
  43.     const tdMake = document.createElement('td');
  44.     tdMake.textContent = make;
  45.     trElement.appendChild(tdMake);
  46.  
  47.     const tdModel = document.createElement('td')
  48.     tdModel.textContent = model;
  49.     trElement.appendChild(tdModel);
  50.  
  51.     const tdYear = document.createElement('td')
  52.     tdYear.textContent = product;
  53.     trElement.appendChild(tdYear);
  54.  
  55.     const tdFuel = document.createElement('td')
  56.     tdFuel.textContent = fuel;
  57.     trElement.appendChild(tdFuel);
  58.  
  59.     const tdOriginPricce = document.createElement('td');
  60.     tdOriginPricce.textContent = oPrice
  61.     trElement.appendChild(tdOriginPricce)
  62.  
  63.     const tdSell = document.createElement('td');
  64.     tdSell.textContent = sPrice;
  65.     trElement.appendChild(tdSell)
  66.  
  67.     const tdButtons = document.createElement('td')
  68.  
  69.     const editBtn = document.createElement('button')
  70.     editBtn.classList.add("action-btn", 'edit')
  71.     editBtn.textContent = "Edit"
  72.     editBtn.addEventListener('click', onEdit)
  73.     tdButtons.appendChild(editBtn);
  74.     const sellBtn = document.createElement('button');
  75.     sellBtn.classList.add('action-btn', "sell");
  76.     sellBtn.textContent = "Sell";
  77.  
  78.     sellBtn.addEventListener('click', onSell)
  79.     tdButtons.appendChild(sellBtn)
  80.  
  81.     trElement.appendChild(tdButtons)
  82.     function onEdit(e) {
  83.  
  84.       trElement.remove()
  85.      
  86.       makeInput.value = make
  87.       modelInput.value = model
  88.       productionInput.value = product
  89.       fuelType.value = fuel
  90.       originPrice.value = oPrice
  91.       sellPrice.value = sPrice
  92.  
  93.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement