Hello,
I am doing the calculator challenge but I am having troubles with the repeat dots.
Basically what I am doing is to push the values of the button into an array and then adding it into the state.
This is the link to my pen:
https://codepen.io/Albertin89/pen/QWbqZRZ?editors=1111
This is what it looks like:
var numbers=[“0”];
var expression =[""];
var totalString;
class Calculator extends React.Component{
constructor(props){
super(props);
this.state = {
input :numbers,
decimalFlag:false,
operatorFlag:false
};
this.getVal = this.getVal.bind(this);
this.deleteAll = this.deleteAll.bind(this);
this.getTotal = this.getTotal.bind(this);
this.backOne = this.backOne.bind(this);
}//construtor
getVal(e){
//let currentNumber = this.state.input;
var ButtonName = event.target.innerText;
numbers.push(ButtonName);
//console.log(numbers)
if(numbers[0]==='0'&&numbers[1]>0||numbers[1]==="."){
numbers.shift();
}
if(numbers[1]==='0'){
numbers.shift();
}
this.setState({
input :numbers
})
totalString=this.state.input.join("");
} //getVal