-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculator.jsx
49 lines (40 loc) · 1.29 KB
/
calculator.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import React from "react"
import TempInput from "./tempinput"
import "./convetor";
import { tyrConvert,toCelsius,toFahrenheit } from "./convetor";
import BoilingVerdict from "./boil";
class Calculator extends React.Component {
constructor(props){
super(props);
this.handleCelsiusChange = this.handleCelsiusChange.bind(this);
this.handleFahrenheitChange=this.handleFahrenheitChange.bind(this);
this.state = {temp:"",scale:"c"};
}
handleCelsiusChange(temp){
this.setState({scale:"c",temp});
}
handleFahrenheitChange(temp){
this.setState({scale:"f",temp});
}
render(){
const scale = this.state.scale;
const temp = this.state.temp;
const celsius = scale === "f"? tyrConvert(temp,toCelsius):temp;
const fahrenheit = scale === "c"? tyrConvert(temp,toFahrenheit):temp;
console.log(this.state);
return(
<div>
<TempInput
scale="c"
temp={celsius}
onTempChange={this.handleCelsiusChange}/>
<TempInput
scale="f"
temp={fahrenheit}
onTempChange={this.handleFahrenheitChange}/>
<BoilingVerdict/>
</div>
)
}
}
export default Calculator;