Advertisement
ilianrusev

Untitled

Feb 18th, 2022
11
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function calculator() {
  2. const html = { s1: "", s2: "", output: "" }
  3.  
  4. function calc(a, b, sign) {
  5. const signs = { "+": (a, b) => a + b, "-": (a, b) => a - b }
  6.  
  7. return signs[sign](Number(a), Number(b))
  8. }
  9.  
  10. return {
  11. init: (a, b, c) => {
  12. html.s1 = document.querySelector(a)
  13. html.s2 = document.querySelector(b)
  14. html.output = document.querySelector(c)
  15. },
  16. add: () =>
  17. (html.output.value = calc(html.s1.value, html.s2.value, "+")),
  18. subtract: () =>
  19. (html.output.value = calc(html.s1.value, html.s2.value, "-")),
  20. }
  21. }
Advertisement
RAW Paste Data Copied
Advertisement