Skip to content
Snippets Groups Projects
Commit 284dc41a authored by Marcel Mernitz's avatar Marcel Mernitz
Browse files

Delete application.js

parent 295f4bbf
No related branches found
No related tags found
No related merge requests found
import Controller from '@ember/controller';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
export default class ApplicationController extends Controller {
@tracked a;
@tracked b;
@tracked operator = "+";
@tracked result;
@tracked calculated = false;
@tracked historyAvailable = false;
@tracked calculationsList = [];
@action
calculate(event) {
event.preventDefault();
if (this.operator === "+") {
this.result = parseInt(this.a) + parseInt(this.b);
this.calculated = true;
this.calculationsList.pushObject({calc: `${this.a} ${this.operator} ${this.b} = ${this.result}`});
console.log(`list: ${this.calculationsList}`)
this.historyAvailable = true;
console.log(`a: ${this.a}, b: ${this.b}, operator: ${this.operator}, result: ${this.result}, calculated: ${this.calculated}`)
} else if (this.operator === "-") {
this.result = parseInt(this.a) - parseInt(this.b);
this.calculated = true;
this.calculationsList.pushObject({calc: `${this.a} ${this.operator} ${this.b} = ${this.result}`});
console.log(`list: ${this.calculationsList}`)
this.historyAvailable = true;
console.log(`a: ${this.a}, b: ${this.b}, operator: ${this.operator}, result: ${this.result}, calculated: ${this.calculated}`)
} else if (this.operator === "*") {
this.result = parseInt(this.a) * parseInt(this.b);
this.calculated = true;
this.calculationsList.pushObject({calc: `${this.a} ${this.operator} ${this.b} = ${this.result}`});
console.log(`list: ${this.calculationsList}`)
this.historyAvailable = true;
console.log(`a: ${this.a}, b: ${this.b}, operator: ${this.operator}, result: ${this.result}, calculated: ${this.calculated}`)
}else if (this.operator === "%") {
this.result = parseInt(this.a) % parseInt(this.b);
this.calculated = true;
this.calculationsList.pushObject({calc: `${this.a} ${this.operator} ${this.b} = ${this.result}`});
console.log(`list: ${this.calculationsList}`)
this.historyAvailable = true;
console.log(`a: ${this.a}, b: ${this.b}, operator: ${this.operator}, result: ${this.result}, calculated: ${this.calculated}`)
} else if (this.operator === "/" && parseInt(this.b) !== 0) {
this.result = parseInt(this.a) / parseInt(this.b);
this.calculated = true;
this.calculationsList.pushObject({calc: `${this.a} ${this.operator} ${this.b} = ${this.result}`});
console.log(`list: ${this.calculationsList}`)
this.historyAvailable = true;
console.log(`a: ${this.a}, b: ${this.b}, operator: ${this.operator}, result: ${this.result}, calculated: ${this.calculated}`)
}
}
@action
setNewOperator(value) {
this.operator = value;
}
@action
recalculate(params) {
let splitted = params.split(" "), arr = [];
console.log(splitted)
this.a = splitted[0];
this.operator = splitted[1];
this.b = splitted[2];
this.calculate(event);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment