I want to display the text in the display section where the input via the buttons are aligned to the right and when the text exceeds the width of the display div it gets overflowed to the left,ie the most most recent inputs should be displayed.
but the problem occurs when i start inputting special characters. In the console input appears correctly, in order but on the display the order starts getting jumble when other characters are inputted.
is it because of the direction property?
const display = document.getElementById('display');
const numbers = document.getElementsByClassName('nums');
for (let i = 0; i < numbers.length; i++) {
console.log(numbers[i].value)
numbers[i].addEventListener('click', () => {
console.log(display.innerText + `${numbers[i].value}`)
display.innerText = display.innerText + `${String(numbers[i].value)}`;
})
}
* {
box-sizing: border-box;
}
body {
margin: 0px;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
}
button {
padding: 10px 18px
}
.operations button {
margin-top: 5px;
padding: 10px 15px;
}
.numbers {
width: 80%;
display: block;
/* flex-direction; */
/* justify-content: space-evenly; */
align-items: center;
}
.container {
border: 1px solid black;
padding: 20px;
}
.row {
display: flex;
flex-direction: row;
justify-content: space-around;
/* align-items: center; */
margin: 7px 0;
}
.display {
border: 1px solid black;
width: 200px;
height: 30px;
margin: 10px;
text-align: right;
overflow: hidden;
direction: rtl;
}
.butts {
display: flex;
}
.operations {
display: flex;
margin-top: 2px;
flex-direction: column;
margin-left: 5px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div class="container">
<div class="display" id='display'></div>
<div class="butts">
<div class="numbers">
<div class="row">
<button class="nums" value="1">1</button>
<button class="nums" value="2">2</button>
<button class="nums" value="3">3</button>
</div>
<div class="row">
<button class="nums" value="4">4</button>
<button class="nums" value='5'>5</button>
<button class="nums" value='6'>6</button>
</div>
<div class="row">
<button class="nums" value="7">7</button>
<button class="nums" value="8">8</button>
<button class="nums" value="9">9</button>
</div>
<div class="row">
<button class="nums" value="0" style='width:55%'>0</button>
<button classs="eqs" value="=" style='width:35%'>=</button>
</div>
</div>
<div class="operations">
<button class="nums" value="+">+</button>
<button class="nums" value="a">a</button>
<button class="nums" value="*">*</button>
<button class="nums" value="/">/</button>
</div>
</div>
</div>
</body>
</html>
