Проблем с 01. Car Dealers от JS Advanced Exam - 25 Jun 2022
Здравейте, получавам 23/100, някой може ли да ми помогне ?
Благодаря :)
задача:
https://judge.softuni.org/Contests/Practice/Index/3519#0
код:
window.addEventListener("load", solve)
function solve() {
let makeEl = document.getElementById("make");
let modelEl = document.getElementById("model");
let yearEl = document.getElementById("year");
let fuelEl = document.getElementById("fuel");
let priceEl = document.getElementById("original-cost");
let sellEl = document.getElementById("selling-price");
let publishBtn = document.getElementById("publish");
let currDif = 0;
publishBtn.addEventListener("click", publish);
function publish(e) {
e.preventDefault();
if (makeEl.value === ""
|| modelEl.value === ""
|| yearEl.value === ""
|| priceEl.value === ""
|| sellEl.value === ""
|| fuelEl.value === "") {
return
};
if (priceEl.value < 0 || sellEl.value < 0 || priceEl.value >= sellEl.value) {
return;
}
let make = makeEl.value;
let model = modelEl.value;
let year = yearEl.value;
let fuel = fuelEl.value;
let price = priceEl.value;
let sell = sellEl.value;
let tBody = document.getElementById("table-body");
let row = document.createElement("tr");
// row.setAttribute("class", "row")
//row.classList.add("row")
row.className = "row"
let tdMake = document.createElement("td");
tdMake.textContent = make;
let tdModel = document.createElement("td");
tdModel.textContent = model;
let tdYear = document.createElement("td");
tdYear.textContent = year;
let tdFuel = document.createElement("td");
tdFuel.textContent = fuel;
let tdPrice = document.createElement("td");
tdPrice.textContent = price;
let tdSell = document.createElement("td");
tdSell.textContent = sell;
let editBtn = document.createElement("button");
editBtn.textContent = "Edit";
editBtn.className = "action-btn edit"
let sellBtn = document.createElement("button");
sellBtn.textContent = "Sell";
sellBtn.className = "action-btn sell"
row.appendChild(tdMake);
row.appendChild(tdModel);
row.appendChild(tdYear);
row.appendChild(tdFuel);
row.appendChild(tdPrice);
row.appendChild(tdSell);
row.appendChild(editBtn);
row.appendChild(sellBtn);
tBody.appendChild(row);
makeEl.value = ""
modelEl.value = ""
yearEl.value = ""
fuelEl.value = ""
priceEl.value = ""
sellEl.value = ""
editBtn.addEventListener("click", edit)
function edit(e) {
document.getElementsByClassName("action-btn edit").disabled = true;
makeEl.value = make;
modelEl.value = model;
yearEl.value = year;
fuelEl.value = fuel;
priceEl.value = price;
sellEl.value = sell;
row.parentNode.remove(row);
}
sellBtn.addEventListener("click", sellComm)
function sellComm(e) {
let ul = document.getElementById("cars-list");
let li = document.createElement("li");
li.className = "each-list"
let span1 = document.createElement("span");
span1.textContent = `${make} ${model}`;
let span2 = document.createElement("span");
span2.textContent = year;
let span3 = document.createElement("span");
span3.textContent = Number(sell) - Number(price);
li.appendChild(span1);
li.appendChild(span2);
li.appendChild(span3);
ul.append(li);
let profitField = document.getElementById("profit")
let difference = Number(sell) - Number(price);
currDif += difference
profitField.textContent = currDif
row.parentNode.remove(row);
}
}
}
Благодаря !