Skip to content

Commit

Permalink
shuffle
Browse files Browse the repository at this point in the history
  • Loading branch information
uribgp committed Aug 24, 2020
1 parent 4807d16 commit a1069b9
Show file tree
Hide file tree
Showing 33,884 changed files with 39,105 additions and 3,081,973 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
15,191 changes: 15,191 additions & 0 deletions W14/W14D3/react-calculator-solution/package-lock.json

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions W14/W14D3/react-calculator-solution/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "calculator",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.5.0",
"@testing-library/user-event": "^7.2.1",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-scripts": "3.4.1"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
17 changes: 17 additions & 0 deletions W14/W14D3/react-calculator-solution/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<title>React App</title>
</head>
<body>
<div id="root"></div>
</body>
</html>
11 changes: 11 additions & 0 deletions W14/W14D3/react-calculator-solution/src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react';
import Calculator from './Calculator';

const App = () => (
<div className="App">
<h1>Calculator</h1>
<Calculator />
</div>
);

export default App;
67 changes: 67 additions & 0 deletions W14/W14D3/react-calculator-solution/src/Calculator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import React from "react";

class Calculator extends React.Component {
constructor(props) {
super(props);
this.state = {
result: 0,
num1: "",
num2: "",
};
}

handleFirstNum = e => {
const parsedNum = parseInt(e.target.value, 10);
const num1 = isNaN(parsedNum) ? "" : parsedNum;
this.setState({ num1 });
}

handleSecondNum = e => {
const parsedNum = parseInt(e.target.value, 10);
const num2 = isNaN(parsedNum) ? "" : parsedNum;
this.setState({ num2 });
}

add = () => {
const result = this.state.num1 + this.state.num2;
this.setState({ result });
}

subtract = () => {
const result = this.state.num1 - this.state.num2;
this.setState({ result });
}

multiply = () => {
const result = this.state.num1 * this.state.num2;
this.setState({ result });
}

divide = () => {
const result = this.state.num1 / this.state.num2;
this.setState({ result });
}

clear = () => {
this.setState({ num1: "", num2: "", result: 0 });
}

render() {
const { num1, num2, result } = this.state;
return (
<div>
<h1>Result: {result}</h1>
<input onChange={this.handleFirstNum} value={num1} placeholder="First number" />
<input onChange={this.handleSecondNum} value={num2} placeholder="Second number" />
<br />
<button onClick={this.add}>+</button>
<button onClick={this.subtract}>-</button>
<button onClick={this.multiply}>*</button>
<button onClick={this.divide}>/</button>
<button onClick={this.clear}>Clear</button>
</div>
);
}
}

export default Calculator;
10 changes: 10 additions & 0 deletions W14/W14D3/react-calculator-solution/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
);
Loading

0 comments on commit a1069b9

Please sign in to comment.