function addWin() {
const winsList = document.querySelector('.wins__list');
const inputBet = document.querySelector('input[name="bet"]');
const inputSum = document.querySelector('input[name="sum"]');
const btnGetValues = document.querySelector('#btnGetValues');
const winArray = [];
function arrayWins(bet, sum, x) {
winArray.push({bet, sum, x});
}
let renderItems = (array) => {
let items = array.map((el) => {
return `<li class = "win wins__item">
<div class="win__char win__bet"> Ставка: ${el.bet} </div>
<div class="win__char win__sum"> Выигрыш: ${el.sum}</div>
<div class="win__char win__x"> X: ${el.x}</div>
</li>`
});
winsList.innerHTML = items.join(' ');
};
btnGetValues.addEventListener('click', getValues);
function getValues() {
const winBet = Number(inputBet.value);
const winSum = Number(inputSum.value)
const winX = Number((winSum / winBet).toFixed(2));
arrayWins(winBet, winSum, winX);
winArray.sort((min, max) => min.x < max.x ? 1 : -1);
renderItems(winArray);
console.log(winArray);
}
}
addWin();
<div class="block"></div>
<div class="block"></div>
<div class="block"></div>
.block{
margin: 10px;
width: 100px;
height: 100px;
text-align: center;
background-color: #447;
}
window.addEventListener('mousedown', function(e) {
if(e.target.className == 'block') {
e.target.onmousemove = function(e) {
e.target.style.position = "absolute";
e.target.style.left = e.pageX-e.target.offsetWidth/2+"px";
e.target.style.top = e.pageY-e.target.offsetHeight/2+"px";
}
e.target.onmouseout = function(e) {
e.target.style.position = "absolute";
e.target.style.left = e.pageX-e.target.offsetWidth/2+"px";
e.target.style.top = e.pageY-e.target.offsetHeight/2+"px";
}
e.target.onmouseup = function(e) {
e.target.onmousemove = null;
e.target.onmouseout = null;
}
}
});