Skip to content

Erro na aula C11  #1

@JairoAlves23

Description

@JairoAlves23

@anthony1910 @joaohcrangel @glauciodaniel

Boa noite, favor verificar qual erro nesse codigo no metodo this._Operation.push(value) não funciona.

class CalcController {

constructor() {
    this._locale = 'pt-BR';
    this._Operation = [];
    this._displayCalcEl = document.querySelector("#display");
    this._dateEl = document.querySelector("#data");
    this._timeEl = document.querySelector("#hora"); 
    this._currentDate;
    this.initialize();
    this.initButtonsEvents();
};

initialize(){
    this.setDisplayDateTime();
    setInterval(() =>{
        this.setDisplayDateTime();
    },1000);
};

setDisplayDateTime(){
    this.displayDate = this.currentDate.toLocaleDateString(this._locale);
    this.displayTime = this.currentDate.toLocaleTimeString(this._locale);
};

addEventListenerAll(element, events, fn){
   
    events.split(' ').forEach(event =>{
        element.addEventListener(event,fn,false);
    });

};

clearAll(){
    this._Operation = [];
};

clearEntry(){
    this._Operation.pop(); 
}

setError(){
    this.displayCalc = "Error";
}

getLastOperation(){
    return this._Operation[this._Operation-1];
}

isOperator(value) {
  return (['+','-','/','*','%'].indexOf(value) > - 1); 
    
}


addOperation(value){
    
    console.log(value); 
    console.log(this.getLastOperation());
    console.log(this.isOperator());
    
    if(isNaN(this.getLastOperation())){
        if (this.isOperator(value)) {
            this._Operation[this._Operation.length - 1] = value;
        } else if (isNaN(value)) {
           console.log(value);
        } else {
            this._Operation.push(value);
        }
        } else{
        let newValue = this.getLastOperation().toString() + value.toString();
        this._Operation.push(newValue);
    }
}

execButton(value) {
    switch (value) {
        case 'ac':
            this.clearAll();
            break;
        case 'ce':
            this.clearEntry();
            break;
        case 'soma':
            this.addOperation('+');   
            break;
            
        case 'subtracao':
            this.addOperation('-');
            break;
        
        case 'multiplicacao':
            this.addOperation('*');
            break;
        
        case 'divisao':
            this.addOperation('/');
            break;
        
        case 'porcento':
            this.addOperation('%');
            break;
        
        case 'igual':
            this.addOperation('=');
            break;

        case 'ponto':
            this.addOperation('-');
        break;

            case '0':
            case '1':
            case '2':
            case '3':
            case '4':
            case '5':
            case '6':
            case '7':
            case '8':
            case '9':
                this.addOperation(parseInt(value));
                
                break;

        default:
            this.setError();
            break;
    }
}

initButtonsEvents(){
    let buttons = document.querySelectorAll("#buttons > g, #parts > g");
    buttons.forEach((button,index)=>{
      
        this.addEventListenerAll(button,"click drag" , e=>{
            let txtbutton = (button.className.baseVal.replace("btn-",""));
            this.execButton(txtbutton);
       });

       this.addEventListenerAll(button, "mouseover mouseup mousedown", e=> {
        button.style.cursor = "pointer";
    });

    });     
};  
    
get displayTime() {
    return this._timeEl.innerHTML;
}
set displayTime(value) {
    this._timeEl.innerHTML = value;
}
get displayDate() {
    return this._dateEl.innerHTML;
}
set displayDate(value) {
    this._dateEl.innerHTML = value;
}
get displayCalc(){
    return this._displayCalcEl.innerHTML;
}
set displayCalc(value){
 this._displayCalcEl.innerHTML = value;
}
get currentDate(){
    return new Date();
}
set currentDate(value){
    this._currentDate.innerHTML = value;
}

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions