diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..b73986e Binary files /dev/null and b/.DS_Store differ diff --git a/README.md b/README.md index 39633cd..82950c7 100644 --- a/README.md +++ b/README.md @@ -1,26 +1,26 @@ -# 🔢 Week01 Alumni Project: Calculator +# OOP Calculator +A calculator done using object-oriented programming. -### Goal: Build a Simple Calculator using JS OOP best practices +**Link to project:** +https://quirky-aryabhata-167d92.netlify.com/ -### What it should look like: +![alt tag](oop_calc.png) -![Calculator](calculator.jpg) +## How It's Made: -### How to submit your code for review: +**Tech used:** little bit of HTML, CSS & a lot of Javascript -- Fork and clone this repo -- Create a new branch called answer -- Checkout answer branch -- Push to your fork -- Issue a pull request -- Your pull request description should contain the following: - - (1 to 5 no 3) I completed the challenge - - (1 to 5 no 3) I feel good about my code - - Anything specific on which you want feedback! +So I took a previous version of a JS calculator and I converted it into an object-oriented program. -Example: -``` -I completed the challenge: 5 -I feel good about my code: 4 -I'm not sure if my constructors are setup cleanly... -``` +## Lessons Learned: + +This was the first project i did with OOP so this helped me with learning the structure and overall syntax of OOP. + +## Examples: +Take a look at these couple examples that I have in my own portfolio: + +**Palettable:** https://github.com/alecortega/palettable + +**Twitter Battle:** https://github.com/alecortega/twitter-battle + +**Patch Panel:** https://github.com/alecortega/patch-panel diff --git a/css/.DS_Store b/css/.DS_Store new file mode 100644 index 0000000..0c9cb17 Binary files /dev/null and b/css/.DS_Store differ diff --git a/css/style.css b/css/style.css new file mode 100644 index 0000000..db8da94 --- /dev/null +++ b/css/style.css @@ -0,0 +1,7 @@ +*{ + box-sizing: border-box; +} +html,body{ + margin: 0; + padding: 0; +} diff --git a/index.html b/index.html new file mode 100644 index 0000000..6653493 --- /dev/null +++ b/index.html @@ -0,0 +1,27 @@ + + + + + + + + + + +
+ + +
+
+ - +
+
+ * +
+
+ / +
+

Hello, World!

+ + + + diff --git a/js/.DS_Store b/js/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/js/.DS_Store differ diff --git a/js/main.js b/js/main.js new file mode 100644 index 0000000..8133149 --- /dev/null +++ b/js/main.js @@ -0,0 +1,70 @@ +// objects come from here +class Calculator { + + // Add two values together and returns the sum + add (val1, val2) { + var sum = val1 + val2 + return sum + } + // subtract two values together and returns the difference + subtract (val1, val2) { + var diff = val1 - val2 + return diff + } + // multiply two values together and returns the product + multiply (val1, val2) { + var prod = val1 * val2 + return prod + } + // divides two values together and returns the quotent + divide (val1, val2) { + var quo = val1 / val2 + return quo + } +}; + +//load calc when page loads +const calc = new Calculator(); + +// event listers for 4 different functions +document.getElementById('add').onclick = addVal +document.getElementById('sub').onclick = subVal +document.getElementById('multi').onclick = divVal +document.getElementById('divi').onclick = multiVal + +// +function addVal(){ + var val1 = parseInt(document.getElementById('val1').value) + var val2 = parseInt(document.getElementById('val2').value) + var sum = calc.add(val1, val2) + + // displays sum to DOM + document.getElementsByTagName('h2')[0].innerHTML = sum +} + +function subVal(){ + var val1 = parseInt(document.getElementById('val1').value) + var val2 = parseInt(document.getElementById('val2').value) + var diff = calc.subtract(val1, val2) + + // displays difference to DOM + document.getElementsByTagName('h2')[0].innerHTML = diff +} + +function divVal(){ + var val1 = parseInt(document.getElementById('val1').value) + var val2 = parseInt(document.getElementById('val2').value) + var quotent = calc.multiply(val1, val2) + + // displays quotent to DOM + document.getElementsByTagName('h2')[0].innerHTML = quotent +} + +function multiVal(){ + var val1 = parseInt(document.getElementById('val1').value) + var val2 = parseInt(document.getElementById('val2').value) + var product = calc.divide(val1, val2) + + // displays product to DOM + document.getElementsByTagName('h2')[0].innerHTML = product +} diff --git a/oop_calc.png b/oop_calc.png new file mode 100644 index 0000000..eeea324 Binary files /dev/null and b/oop_calc.png differ