<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Un calculator simplu</title>
  </head>
  <body>
    <h1>Calculator</h1>
    <input type="number" placeholder="a" id="numberA" class="numbers op">
    <input type="number" placeholder="b" id="numberB" class="numbers op">
    <button onclick="sub()">-</button>
    <button onclick="add()">+</button>
    <button onclick="mul()">*</button>
    <button onclick="div()">/</button>
    <button onclick="pow()">^</button>
    <button onclick="sqrt()">sqrt</button>
    <code id="result"><span>Result</span></code>
    <ul id="history"></ul>

    <script src="index.js"></script>
  </body>
</html>
const numberA = document.querySelector('#numberA');
const numberB = document.querySelector('#numberB');
const result = document.querySelector('#result');
const history = document.querySelector('#history');
function round(r) {
  return Math.round(r * 1e10) / 1e10;
}
function sub() {
  const a = +numberA.value;
  const b = +numberB.value;
  result.innerText = round(a - b);
  history.innerHTML += '<li>1 + 2 = 4</li>';
}
function add() {
  const a = +numberA.value;
  const b = +numberB.value;
  result.innerText = round(a + b);
}
function mul() {
  const a = +numberA.value;
  const b = +numberB.value;
  result.innerText = round(a * b);

}
function div() {
  const a = +numberA.value;
  const b = +numberB.value;
  result.innerText = round(a / b);
}
function pow() {
  const a = +numberA.value;
  const b = +numberB.value;
  result.innerText = round(a ** b);
}
function sqrt() {
  const a = +numberA.value;
  const b = +numberB.value;
  result.innerText = round(Math.sqrt(a, b));
}

// let n = 1;
// for (let i = 0; i < 10; i++) {
//   n = n ? 0 : 1;
//   // n = i % 2;
//   document.write(n);
// }

// const number = 987654321;
// let initial = number;
// let final = 0;
// while(initial) {
//   final = final * 10 + initial % 10;
//   initial = Math.floor(initial / 10);
// }
// console.log(number, final);

results matching ""

    No results matching ""