**Hi, I’m making a simple calculator, I’m trying to clear the output text when I click on the Del button. Right now it only clears input text. Please assist
**
your text
import React, { Component } from ‘react’;
your text
import { StyleSheet, Text, View, Button, TouchableOpacity } from ‘react-native’;
your text
export default class App extends Component {
your text
constructor() {
your text
super();
your text
this.state = {
your text
calculationText: “”,
your text
resultText: “”,
your text
};
your text
this.operations = [‘Del’, ‘/’, ‘*’, ‘-‘, ‘+’];
your text
}
your text
calculateResult() {
your text
const text = this.state.calculationText;
your text
console.log(text, eval(text));
your text
this.setState({
your text
resultText: eval(text)
your text
})
your text
}
your text
validate(){
your text
const text = this.state.calculationText
your text
switch(text.slice(-1)){
your text
case ‘+’:
your text
case ‘-‘:
your text
case ‘*’:
your text
case ‘/’:
your text
return false
your text
}
your text
return true
your text
}
your text
buttonPressed(text) {
your text
//console.log(text);
your text
if (text == ‘=’) {
your text
return this.validate() && this.calculateResult(this.state.calculationText);
your text
}
your text
this.setState({
your text
calculationText: this.state.calculationText + text,
your text
});
your text
}
your text
operate(operation) {
your text
switch (operation) {
your text
case ‘Del’:
your text
console.log(this.state.calculationText);
your text
let text = this.state.calculationText.split(”);
your text
text.pop();
your text
this.setState({
your text
calculationText: text.join(”),
your text
});
your text
break;
your text
case ‘/’:
your text
case ‘*’:
your text
case ‘-‘:
your text
case ‘+’:
your text
const lastCHar = this.state.calculationText.split(”).pop();
your text
if (this.operations.indexOf(lastCHar) > 0) return;
`your text` if (this.state.text == '') return;
`your text` this.setState({
`your text` calculationText: this.state.calculationText + operation,
`your text` });
your text
}
your text
}
your text
render() {
your text
let ops = [];
your text
for (let i = 0; i < 5; i++) {
your text
ops.push(
your text
<TouchableOpacity
your text
style={styles.btn}
your text
onPress={() => this.operate(this.operations[i])}>
your text
your text
{this.operations[i]}
your text
your text
your text
);
your text
}
your text
return (
your text
your text
your text
{this.state.calculationText}
your text
your text
your text
your text
your text
{rows}
your text
`your text`<View style={styles.operations}>
`your text` {ops}
`your text` </View>
`your text` </View>
`your text` </View>
your text
);
your text
}