another change to hopefully trigger webhook
This commit is contained in:
		
							parent
							
								
									65e575f9e4
								
							
						
					
					
						commit
						ea48cdb7c3
					
				|  | @ -4,7 +4,6 @@ import Calculator from "./Components/Calculator"; | ||||||
| function App() { | function App() { | ||||||
|   return ( |   return ( | ||||||
|     <div className="App"> |     <div className="App"> | ||||||
|       I changed something else! |  | ||||||
|       <Calculator /> |       <Calculator /> | ||||||
|     </div> |     </div> | ||||||
|   ); |   ); | ||||||
|  |  | ||||||
|  | @ -2,112 +2,151 @@ import { useState } from "react"; | ||||||
| import KeyPad from "./KeyPad"; | import KeyPad from "./KeyPad"; | ||||||
| 
 | 
 | ||||||
| export default function Calculator(props) { | export default function Calculator(props) { | ||||||
|     const [main, setMain] = useState("0") |   const [main, setMain] = useState("0"); | ||||||
|     const [memory, setMemory] = useState("") |   const [memory, setMemory] = useState(""); | ||||||
|     const [operation, setOperation] = useState("") |   const [operation, setOperation] = useState(""); | ||||||
|     const [on, setOn] = useState(true) |   const [on, setOn] = useState(true); | ||||||
| 
 | 
 | ||||||
|   const map = { |   const map = { | ||||||
|     conc: (numberString) => { |     conc: (numberString) => { | ||||||
|             if(main.length<=9){ |       if (main.length <= 9) { | ||||||
|         if (main[0] === "0") { |         if (main[0] === "0") { | ||||||
|                     setMain(prev => prev.slice(1) + numberString) |           setMain((prev) => prev.slice(1) + numberString); | ||||||
|         } else { |         } else { | ||||||
|                     setMain(prev => prev + numberString) |           setMain((prev) => prev + numberString); | ||||||
|         } |         } | ||||||
|       } |       } | ||||||
|     }, |     }, | ||||||
| 
 | 
 | ||||||
|         zero: function () { this.conc("0") }, |     zero: function () { | ||||||
|         one: function () { this.conc("1") }, |       this.conc("0"); | ||||||
|         two: function () { this.conc("2") }, |     }, | ||||||
|         three: function () { this.conc("3") }, |     one: function () { | ||||||
|         four: function () { this.conc("4") }, |       this.conc("1"); | ||||||
|         five: function () { this.conc("5") }, |     }, | ||||||
|         six: function () { this.conc("6") }, |     two: function () { | ||||||
|         seven: function () { this.conc("7") }, |       this.conc("2"); | ||||||
|         eight: function () { this.conc("8") }, |     }, | ||||||
|         nine: function () { this.conc("9") }, |     three: function () { | ||||||
|  |       this.conc("3"); | ||||||
|  |     }, | ||||||
|  |     four: function () { | ||||||
|  |       this.conc("4"); | ||||||
|  |     }, | ||||||
|  |     five: function () { | ||||||
|  |       this.conc("5"); | ||||||
|  |     }, | ||||||
|  |     six: function () { | ||||||
|  |       this.conc("6"); | ||||||
|  |     }, | ||||||
|  |     seven: function () { | ||||||
|  |       this.conc("7"); | ||||||
|  |     }, | ||||||
|  |     eight: function () { | ||||||
|  |       this.conc("8"); | ||||||
|  |     }, | ||||||
|  |     nine: function () { | ||||||
|  |       this.conc("9"); | ||||||
|  |     }, | ||||||
|     decimal: function () { |     decimal: function () { | ||||||
|       if (!/\./g.test(main)) { |       if (!/\./g.test(main)) { | ||||||
|                 this.conc(".") |         this.conc("."); | ||||||
|       } |       } | ||||||
|     }, |     }, | ||||||
| 
 | 
 | ||||||
|         add: function () { this.rcvOperator("add") }, |     add: function () { | ||||||
|         subtract: function () { this.rcvOperator("subtract") }, |       this.rcvOperator("add"); | ||||||
|         multiply: function () { this.rcvOperator("multiply") }, |     }, | ||||||
|         divide: function () { this.rcvOperator("divide") }, |     subtract: function () { | ||||||
|  |       this.rcvOperator("subtract"); | ||||||
|  |     }, | ||||||
|  |     multiply: function () { | ||||||
|  |       this.rcvOperator("multiply"); | ||||||
|  |     }, | ||||||
|  |     divide: function () { | ||||||
|  |       this.rcvOperator("divide"); | ||||||
|  |     }, | ||||||
| 
 | 
 | ||||||
|     rcvOperator: function (operator) { |     rcvOperator: function (operator) { | ||||||
|       if (main === "-") { |       if (main === "-") { | ||||||
|                 setMain("") |         setMain(""); | ||||||
|       } else if (main !== "") { |       } else if (main !== "") { | ||||||
|         if (memory === "") { |         if (memory === "") { | ||||||
|                     setMemory(main) |           setMemory(main); | ||||||
|         } else { |         } else { | ||||||
|                     setMemory(prev => { return this.calculate(main, prev) }) |           setMemory((prev) => { | ||||||
|  |             return this.calculate(main, prev); | ||||||
|  |           }); | ||||||
|         } |         } | ||||||
|                 setMain("") |         setMain(""); | ||||||
|       } |       } | ||||||
|       if (main === "" && operator === "subtract") { |       if (main === "" && operator === "subtract") { | ||||||
|                 setMain(prev => { |         setMain((prev) => { | ||||||
|           if (prev[0] !== "-") { |           if (prev[0] !== "-") { | ||||||
|                         return "-" + prev |             return "-" + prev; | ||||||
|           } |           } | ||||||
|                 }) |         }); | ||||||
|       } else { |       } else { | ||||||
|                 setOperation(operator) |         setOperation(operator); | ||||||
|       } |       } | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
|     }, |     }, | ||||||
| 
 | 
 | ||||||
|     operations: { |     operations: { | ||||||
|             add: (a, b) => { return a + b }, |       add: (a, b) => { | ||||||
|             subtract: (a, b) => { return b - a }, |         return a + b; | ||||||
|             multiply: (a, b) => { return a * b }, |       }, | ||||||
|             divide: (a, b) => { return b / a }, |       subtract: (a, b) => { | ||||||
|  |         return b - a; | ||||||
|  |       }, | ||||||
|  |       multiply: (a, b) => { | ||||||
|  |         return a * b; | ||||||
|  |       }, | ||||||
|  |       divide: (a, b) => { | ||||||
|  |         return b / a; | ||||||
|  |       }, | ||||||
|     }, |     }, | ||||||
| 
 | 
 | ||||||
|     clear: () => { |     clear: () => { | ||||||
|             setMain("0") |       setMain("0"); | ||||||
|             setMemory("") |       setMemory(""); | ||||||
|             setOperation("") |       setOperation(""); | ||||||
|     }, |     }, | ||||||
|     equals: function () { |     equals: function () { | ||||||
|       if (operation !== "" && main !== "") { |       if (operation !== "" && main !== "") { | ||||||
|                 setMain(prev => { |         setMain((prev) => { | ||||||
|                     return this.calculate(prev, memory) |           return this.calculate(prev, memory); | ||||||
|                 }) |         }); | ||||||
|                 setMemory("") |         setMemory(""); | ||||||
|                 setOperation("") |         setOperation(""); | ||||||
|       } |       } | ||||||
| 
 |  | ||||||
|     }, |     }, | ||||||
|         on:()=>setOn(true), |     on: () => setOn(true), | ||||||
|         off:()=>{ |     off: () => { | ||||||
|             setOn(false) |       setOn(false); | ||||||
|             setMain("0") |       setMain("0"); | ||||||
|             setMemory("") |       setMemory(""); | ||||||
|             setOperation("") |       setOperation(""); | ||||||
|     }, |     }, | ||||||
|     calculate: function (a, b) { |     calculate: function (a, b) { | ||||||
|             const string = this.operations[operation](parseFloat(a), parseFloat(b)).toString() |       const string = this.operations[operation]( | ||||||
|             return string.length<=9?string:string.slice(0,10) |         parseFloat(a), | ||||||
|         } |         parseFloat(b), | ||||||
|     } |       ).toString(); | ||||||
|  |       return string.length <= 9 ? string : string.slice(0, 10); | ||||||
|  |     }, | ||||||
|  |   }; | ||||||
| 
 | 
 | ||||||
|   function handleInput(content) { |   function handleInput(content) { | ||||||
|         map[content]() |     map[content](); | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
|   return ( |   return ( | ||||||
|     <div id="calculator"> |     <div id="calculator"> | ||||||
|       <div id="calculator-content"> |       <div id="calculator-content"> | ||||||
|                 <header><h1>CALCULATOR</h1></header> |         <header> | ||||||
|                 <div id="display-container" className={on?"on":"off"}> |           <h1>CALCULATOR - CI/CD EDITION</h1> | ||||||
|  |         </header> | ||||||
|  |         <div id="display-container" className={on ? "on" : "off"}> | ||||||
|           <p id="memory">{memory}</p> |           <p id="memory">{memory}</p> | ||||||
|           <p id="display">{main}</p> |           <p id="display">{main}</p> | ||||||
|           <p id="operator">{operation}</p> |           <p id="operator">{operation}</p> | ||||||
|  | @ -115,5 +154,6 @@ export default function Calculator(props) { | ||||||
|         <KeyPad handleInput={handleInput} /> |         <KeyPad handleInput={handleInput} /> | ||||||
|       </div> |       </div> | ||||||
|     </div> |     </div> | ||||||
|     ) |   ); | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue