1<div class="calculator">
2
3 <input type="text" class="calculator-screen" value="" disabled />
4
5 <div class="calculator-keys">
6
7 <button type="button" class="operator" value="+">+</button>
8 <button type="button" class="operator" value="-">-</button>
9 <button type="button" class="operator" value="*">×</button>
10 <button type="button" class="operator" value="/">÷</button>
11
12 <button type="button" value="7">7</button>
13 <button type="button" value="8">8</button>
14 <button type="button" value="9">9</button>
15
16
17 <button type="button" value="4">4</button>
18 <button type="button" value="5">5</button>
19 <button type="button" value="6">6</button>
20
21
22 <button type="button" value="1">1</button>
23 <button type="button" value="2">2</button>
24 <button type="button" value="3">3</button>
25
26
27 <button type="button" value="0">0</button>
28 <button type="button" class="decimal" value=".">.</button>
29 <button type="button" class="all-clear" value="all-clear">AC</button>
30
31 <button type="button" class="equal-sign operator" value="=">=</button>
32
33 </div>
34</div>
1let add =(...params) => {
2 let sum = 0;
3 params.forEach(el =>{
4 sum = sum + parseInt(el);
5 })
6 return sum
7}
8
9document.querySelector('.add').addEventListener('click' , function (e) {
10 const adder = document.querySelector('.addinput').value
11 const meow = adder.split(',')
12 let result = add(...meow)
13 if (isNaN(result)) {
14 result = 'ENTER A NUMBER'
15 }
16 document.querySelector('.result').textContent = result
17})
18
19let times =(...params) => {
20 let multiply = 1;
21 params.forEach(el =>{
22 multiply = multiply * el;
23 })
24 return multiply
25}
26
27document.querySelector('.multiply').addEventListener('click' , function (e) {
28 const multiplier = document.querySelector('.multiplyinput').value
29 const moo = multiplier.split(',')
30 let product = times(...moo)
31 if (isNaN(product)) {
32 product = 'ENTER A NUMBER'
33 }
34 document.querySelector('.product').textContent = product
35})
36
37let subtract =(...params) => {
38 let diff = 0;
39 diff = params[0] - params[1]
40 return diff
41}
42
43document.querySelector('.subtract').addEventListener('click' , function (e) {
44 const subtracter = document.querySelector('.subtractinput').value
45 const woof = subtracter.split(',')
46 let diff = subtract(...woof)
47 if (isNaN(diff)) {
48 diff = 'ENTER A NUMBER'
49 }
50 document.querySelector('.difference').textContent = diff
51})
52
53let divide =(...params) => {
54 let quotient = 0;
55 quotient = params[0] / params[1]
56 return quotient
57}
58
59document.querySelector('.divide').addEventListener('click' , function (e) {
60 const divider = document.querySelector('.divideinput').value
61 const moo2 = divider.split(',')
62 let quotient = divide(...moo2)
63 if (isNaN(quotient)) {
64 quotient = 'ENTER A NUMBER'
65 }
66 document.querySelector('.quotient').textContent = quotient
67})
68
1class Calculator {
2 constructor(numbers, num1, num2){
3 this.numbers = numbers;
4 this.num1 = num1;
5 this.num2 = num2;
6 }
7
8 add(numbers){
9 var sum = 0;
10
11 for(let i = 0; i < numbers.length; i++){
12 if(typeof numbers[i] === "number"){
13 sum += numbers[i];
14 }
15 }
16
17 return sum;
18 }
19 multiply (numbers) {
20 let total = 1;
21
22 for (let i = 0; i < numbers.length; i++) {
23 if (typeof numbers[i] === 'number')
24 total *= numbers[i]
25 };
26
27 return total;
28 }
29
30 subtract (num1, num2) {
31 return num1 - num2
32 }
33
34 divide (num1, num2) {
35 return num1 / num2
36 }
37}